query all students

SELECT * FROM student;

selected columns

SELECT name, major
FROM student;

column prefix (will be helpful with “join queries”)

SELECT student.name, student.major
FROM student;

Order

Ascending

SELECT * FROM student
ORDER BY name;

Descending

SELECT *
FROM student
ORDER BY name DESC;

Order by column not selected

SELECT name, major
FROM student
ORDER BY student_id DESC;

Multiple order categories

SELECT * FROM student
ORDER BY major, student_id;

Limit

SELECT * FROM student
LIMIT 2;

With order

SELECT * FROM student
ORDER BY student_id DESC
LIMIT 2;

Where Clause

operator meaning
= equal
> greater
< smaller
>= greater equal
<= smaller equal
<> unequal
SELECT * FROM student
WHERE student_id = 2;
WHERE student_id > 2;
WHERE major = 'Biology';
WHERE major = 'Biology' OR major = 'Math';
WHERE major <> 'Biology';
WHERE major <> 'Biology' AND student_id > 2;

IN word

SELECT * FROM student
WHERE major IN ('Biology', 'Computer', 'Music');
SELECT * FROM student
WHERE name IN ('Gila', 'Sason', 'Simha');