SELECT Record
SELECT name, marks FROM students WHERE marks < 40 ORDER BY marks; is the whole language in one line. SELECT = which columns. FROM = which table. WHERE = which rows. ORDER BY = sort.
SELECT * is fine at home. In interviews, list columns. DISTINCT removes duplicate rows in the result. LIMIT 10 is ‘first 10’ after sorting.
Functions — SELECT COUNT(*), AVG(marks) FROM students; aggregates. They collapse rows unless you GROUP BY.
Trap: WHERE after GROUP BY (illegal — use HAVING). Trap: SELECT extra columns not in GROUP BY (ONLY_FULL_GROUP_BY error).
On the example next to this theory — SELECT Record — sELECT projects columns; WHERE filters; ORDER BY sorts.
FROM students
│ WHERE marks < 40
▼
matching rows
│ SELECT name, marks
▼
result tableSELECT name, marks FROM students WHERE marks < 40;