SQL Flashcards

(29 cards)

1
Q

Is SQL a case-sensitive language?

A

No

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

Every statement must be terminated with:

A

A semi-colon (;)

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

How do you add a comment?

A

Add “–” before

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

Order of operations?

A

Parentheses
Multiplication / division
Addition / subtraction

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

SELECT clause

A

Returns a result set of records from one or more tables

Most commonly used DML command

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

SELECT DISTINCT

A

Removes duplicate values

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

WHERE clause

A

Used to filter data

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

Comparison Operators

A

> , >=

!=

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

Logical Operators

A

Used with WHERE clause

AND (both conditions must be True)

OR (at least one condition must be True)

NOT (to negate a condition)

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

IN Operator

A

Returns values in any of specified values

Example:
WHERE state IN (‘VA’, ‘NY’, ‘CA’)

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

BETWEEN Operator

A

WHERE points BETWEEN 100 AND 200

Inclusive of the values provided

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

LIKE Operator

A

Used in the WHERE clause to search for a specified pattern in a column

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

WHERE first_name LIKE ‘b%’

WHERE first_name LIKE ‘%b’

WHERE first_name LIKE ‘b___’

A

First name starts with b and has any number of characters

First name ends with b and has any number of characters

First name starts with b and ends with exactly 3 characters

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

WHERE first_name REGEXP ‘ey$|on$’

A

Returns first names that end with EY or ON

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

WHERE first_name REGEXP ‘^a’

A

Returns first names that start with ‘a’

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

WHERE first_name REGEXP ‘^my|se’

A

Returns first names that start with MY or contain SE

17
Q

WHERE first_name REGEXP ‘b[ru]’

A

Returns first names that contain B followed by R or U

18
Q

IS NULL Operator

A

Returns records that are null/don’t contain any data

19
Q

ORDER BY Clause

A

Sorts values in ascending order by default

DESC at end of ORDER BY clause to specify descending order

20
Q

LIMIT Clause

A

Returns only a specified number of values

21
Q

LIMIT 6, 3

A

Skips first 6 entries and returns numbers 7, 8, 9

22
Q

JOIN (INNER JOIN)

A

Returns all records that have matching values in both tables

23
Q

LEFT JOIN

A

Returns all records from the left table, and the matched records from the right table

24
Q

RIGHT JOIN

A

Returns all records from the right table, and the matched records from the left table

25
USING Clause
If column names are identical, you can simplify the join with the USING clause SELECT * FROM customers c JOIN orders o USING (customer_id)
26
CROSS JOIN
Combine every value in one table with every value in the other table (color and size) SELECT * FROM colors CROSS JOIN sizes
27
UNION
Combine records from multiple result sets ``` SELECT name, address FROM customers UNION SELECT name, address FROM clients ```
28
Insert a single record
INSERT INTO customers(first_name, phone, points) | VALUES ('Hannah', NULL, DEFAULT)
29
Insert multiple records
INSERT INTO customers(first_name, phone, points) VALUES ('Hannah, NULL, DEFAULT), ('Bob', '1234', 10)