How to use the SELECT statement in SQL

· Category: SQL & Databases

Short answer

SELECT retrieves columns from a table. Specify columns or use * for all columns, then name the table with FROM.

Steps

  1. Select all columns: SELECT * FROM employees;
  2. Select specific columns: SELECT first_name, last_name FROM employees;
  3. Use expressions: SELECT first_name, salary * 1.1 AS new_salary FROM employees;
  4. Eliminate duplicates with SELECT DISTINCT department FROM employees;
  5. Alias tables: SELECT e.first_name FROM employees AS e;

Tips

  • Avoid SELECT * in production queries; name only the columns you need to reduce I/O and network overhead.
  • Use meaningful column aliases to improve readability in result sets and reporting tools.

Common issues

  • Forgetting FROM causes a syntax error in most SQL dialects.
  • Column name typos produce Unknown column errors instead of returning nulls.r