SELECT & SELECT DISTINCT
SELECT chooses which columns you want. FROM names the table. * means all columns — fine for learning, but in real work list only what you need.
SELECT — read columns from a table
SELECT chooses which columns you want. FROM names the table. * means all columns — fine for learning, but in real work list only what you need.
Always start with a small SELECT before adding filters. This habit saves time when a query returns unexpected results.
Real-life example: SELECT is like choosing which columns to copy from a spreadsheet — name and city only, not every hidden column.
-- Specific columns (preferred)
SELECT student_id, full_name, city
FROM students;
-- All columns (quick peek only)
SELECT * FROM students;SELECT DISTINCT — unique values only
DISTINCT removes duplicate rows from the result. Use it when you only care about unique values, such as all cities where students live.
DISTINCT applies to the whole row combination you select, not just one column.
Real-life example: DISTINCT is like asking 'Which cities appear on the list?' without reading every student name twice.
SELECT DISTINCT city
FROM students;
SELECT DISTINCT grade_level, city
FROM students
ORDER BY grade_level, city;