Querying in SQL Flashcards

1
Q

What is the SELECT statement, and what statement is it used with?

A

Basic statement that is used to retrieve data from a SQL database; used with the FROM statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Clause that is used to filter certain results being returned

A

WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are standard numerical operators (6)?

Clause: ???

A

=, !=, , >=

I.E.
Col_name != 4

Clause: WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Number is within range of two values (inclusive)

Clause: ???

A

BETWEEN … AND …

I.E.
Col_name BETWEEN 1.5 AND 5

Clause: WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Number is not within range of two values (inclusive)

Clause: ????

A

NOT BETWEEN … AND …

I.E.
Col_name NOT BETWEEN 3 AND 5

Clause: WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Number exists in a list
String exists in a list
Clause: ????

A

IN (…)

I.E.
Col_name IN (2, 4, 6)
Col_name IN ("A", "B", "C")

Clause: WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Number does not exist in a list
String does not exist in a list
Clause: ????

A

NOT IN (…)

I.E.
Col_name NOT IN (1, 2, 3)
Col_name NOT IN (“A”, “B”, “C”)

Clause: WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Case sensitive exact string comparison

A

=

I.E.
Col_name = “abc”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Case sensitive exact string inequality comparison

A

!=,

I.E.
Col_name != “xyza”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Case INSENSITIVE exact string comparison

A

LIKE

I.E.
Col_name LIKE “fgh”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Case INSENSITIVE exact string inequality comparison

A

NOT LIKE

I.E.
Col_name NOT LIKE “gnhc”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Used anywhere in a string to match a sequence of zero or more characters

Used with something.

A

%

I.E.
Col_name LIKE “%AT%” (matches “AT”, “ATTIC”, “CAT” or even “BRATS”)

used with LIKE and NOT LIKE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Used anywhere in a string to match a single character

Used with something

A

_

I.E.
Col_name LIKE “AN_” (matches “AND”, but not “AN”)

used with LIKE and NOT LIKE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the DISTINCT clause?

With what statement is it used?

A

Discard rows that have a duplicate column value; SELECT statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the ORDER BY clause?

And what is commonly used with it?

A

The ORDER BY clause is a way to sort results by a given column in ascending or descending order.

The LIMIT will reduce the number of rows to return, and OFFSET will specify where to begin counting the number rows from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of the INNER JOIN clause?

A

Process that matches rows from the first table and the second table which have the same key to create a result row with the combined columns from both tables.

17
Q

What is a LEFT JOIN?
RIGHT JOIN?
FULL JOIN?

A

When joining table A to table B, a LEFT JOIN simply includes rows from A regardless of whether a matching row is found in B.

RIGHT JOIN is same as LEFT JOIN but reversed; keeping rows in B regardless of whether a matching row was found in A.

FULL JOIN means that rows from both tables are kept, regardless of whether a there is a matching row in the other table.

18
Q

Clause that IS NULL/IS NOT NULL is used with.

A

WHERE