SELECT Statement

Beginner

⏱️ 7 mins read

What You'll Learn

SELECT retrieves data from one or more tables. You can select all columns with * or specify individual columns. Aliases (AS) rename a column or table for the duration of the query. SQL execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY — SELECT is processed near the end!

Syntax

SELECT * FROM table_name;
SELECT col1, col2 FROM table_name;
SELECT col1 AS alias FROM table_name;

Example

SELECT first_name, salary * 12 AS annual_salary
FROM employees;

-- Multiple columns with aliases
SELECT
  first_name AS name,
  department AS dept,
  hire_date
FROM employees;

Common Mistakes

Using SELECT * in production fetches ALL columns, increasing I/O and network overhead. Always select only the columns you need. Also, aliases defined in SELECT cannot be used in WHERE (because WHERE runs before SELECT).

Interview Tips

Know the SQL execution order cold — FROM, JOIN, WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY, LIMIT. Interviewers frequently ask why you can't use a SELECT alias in a WHERE clause.

Practice

Write a query to fetch 'email' and 'full_name' from the 'profiles' table, showing 'full_name' as 'Customer Name' and 'email' as 'Contact Email'.