SELECT, WHERE & Friends: Querying Basics
How to read and change data with SQL: the SELECT query shape, filtering and sorting with WHERE/ORDER BY/LIMIT, and adding/changing/removing rows with INSERT/UPDATE/DELETE - without the career-defining accidents.
Download EPUB- Asking for Data: SELECT ... FROM Every query starts from the same shape - SELECT which columns FROM which table. Learn to pick specific columns vs. grab everything with *, and how to read the rows-and-columns result set you get back.
- Filtering & Sorting: WHERE, ORDER BY, LIMIT Narrow a query to the rows you actually want with WHERE (=, >, LIKE, IN, AND/OR), put them in order with ORDER BY, and take only the top few with LIMIT - plus the NULL trap that means you must use IS NULL, not = NULL.
- Changing Data: INSERT, UPDATE, DELETE Add rows with INSERT, modify them with UPDATE, and remove them with DELETE - and the career-defining gotcha: an UPDATE or DELETE without a WHERE rewrites or erases every row in the table. Learn the WHERE-first habit and how transactions can undo a mistake.