Selecting from a Table Flashcards

1
Q

SELECT STATEMENT

A

SELECT*FROM tablename

SELECT columnname FROM tablename

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

SELECT WHERE clause

A

SELECT*FROM tablename
WHERE columnname = value
AND columname = value (και με τα δυο)

SELECT*FROM tablename
WHERE columnname = value
OR columnname = value (ολα με αυτα τα δυο)

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

NULL NUMBER

A

SELECT*FROM tablename
WHERE columnname IS NULL

SELECT*FROM tablename
WHERE columnname IS NOT NULL

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

IN, NOT IN

A

SELECT*FROM tablename
WHERE columnname IN (‘’,’’,’‘…)

SELECT*FROM tablename
WHERE columnname NOT IN (‘’,’’,’‘…)
(το ιδιο με το Where clause, αλλα σε αυτο επιλεγεις πολλα..)

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

BETWEEN

A

SELECT*FROM tablename

WHERE columnname BETWEEN values AND values;

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

LIKE

A

SELECT*FROM tablename
WHERE columnname LIKE ‘%value%’; (αναμεσα σε πολλα πριν και μετα)

SELECT*FROM tablename
WHERE columnname LIKE ‘value’; (αναμεσα σε 1 πριν 1 μετα)

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

ORDER BY

A

SELECT*FROM tablename
ORDER BY columnname ASC ή DESC

SELECT*FROM tablename
WHERE columnname = value (ή >,

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

DISTINCT

A

1)
SELECT coffee_origin FROM products; (τα εμφανιζει ολα στο column coffee_origin)

SELECT DISTINCT coffee_origin FROM products; (δεν εμφανιζει τα διπλά, μονο φορα το καθε ενα).
2)
SELECT DISTINCT product_id,customer_id FROM orders
WHERE order_time BETWEEN ‘2017-02-01’ AND ‘2017-02-28’; (εμφανιζει τον συνδυασμο product με customer 1 φορα ομως, εαν υπαρχει το ιδιο σε αλλη μερα δεν το εμφανιζει).

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

LIMIT

A

SELECT*FROM customers
LIMIT 3;
(εμφανιζει τα 3 πρωτα rows)

SELECT*FROM customers
LIMIT 3 OFFSET 5;
(εμφανιζει τις 3 σειρες μετα την πεμπτη σειρα)

SELECT*FROM customers
ORDER BY last_name
LIMIT 3;
(εμφανιζει με order τις 3 πρωτες αλφαβητικα σειρες. μπορεις να βαλεις DESC ή ASC)

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

COLUMN NAME ALIAS

A

SELECT name, price,coffee_origin FROM products;

SELECT name AS coffee, price, cofee_origin AS country FROM products;
(Δεν αλλαζει το ονομα στην database, αλλα μονο στο result το συγκεκριμενο)

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