SQL Tutorial · Revision notes
SQL SELECT, WHERE & Clauses
SELECT reads data from tables. WHERE, ORDER BY, GROUP BY and HAVING help us filter, sort and summarise it. INSERT, UPDATE and DELETE change the data. Aggregate functions like COUNT and SUM calculate totals.
Quick revision
- SELECT columns FROM table. Use WHERE to filter rows.
- AND needs both true. OR needs one true. Use brackets when mixing.
- Use IS NULL for empty values. Use LIKE with % and _ for patterns.
- ORDER BY sorts. Default is ASC. Use DESC for highest first.
- DISTINCT removes duplicates. AS gives an alias.
- GROUP BY makes groups. HAVING filters groups. WHERE filters rows.
- INSERT adds, UPDATE edits, DELETE removes. Always use WHERE with UPDATE and DELETE.
- Aggregates: COUNT, SUM, AVG, MIN, MAX. They skip NULL values.