MySQL Clauses Flashcards

1
Q

SELECT

A

This clause is used to view something in MySQL. It can be called with/without a table.
EX - SELECT * FROM table_name;
SELECT 1 + 2;

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

WHERE

A

This clause is used to provide condition to the SELECT clause.
Evaluated before SELECT.

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

FROM

A

Used to specify the table which we need to display/manipulate.
This is evaluated first.
FROM -> WHERE -> SELECT -> DISTINCT -> ORDER BY

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

ORDER BY

A

Used to order the result set in ASC/DESC order.

Ex - SELECT * FROM table_name ORDER BY column_name ASC/DESC;

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

DISTINCT

A

Used to return only DISTINCT values on the result set.

EX - SELECT DISTINCT(column_name) FROM table_name;

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

IN/NOT IN

A

This clause is used when the column can take only certain discrete values.
Used when we wish to compare to a list of values.
EX - SELECT * FROM emp WHERE city IN (‘NYC’, ‘AU’, ‘DC’);
SELECT * FROM emp WHERE city NOT IN (‘NYC’, ‘AU’, ‘DC’);

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

BETWEEN

A

Used when we want to check if a condition falls in a range.

Ex - SELECT * FROM table_name WHERE column_name BETWEEN lower AND upper;

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

LIKE

A

Used to match pattern (like regex)
Ex - SELECT * FROM table_name WHERE column_name LIKE ‘a%’;

% means 0 or more characters
_ means 1 character

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