What is the SELECT statement?

Answer

The SELECT statement is the most used SQL command — it retrieves data from one or more tables. Basic syntax: SELECT column1, column2 FROM table_name WHERE condition ORDER BY column ASC/DESC LIMIT n;. Key clauses: SELECT * — retrieves all columns (avoid in production — specify columns explicitly for clarity and performance); FROM — specifies the table(s); WHERE — filters rows (uses comparison operators: =, !=, <, >, BETWEEN, IN, LIKE, IS NULL); ORDER BY — sorts results (ASC default, DESC for descending); LIMIT — restricts number of rows returned; OFFSET — skips rows (for pagination: LIMIT 10 OFFSET 20); DISTINCT — removes duplicate rows: SELECT DISTINCT city FROM users; Aliases: SELECT first_name AS name — rename columns in output. Execution order (not syntax order): FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT.