Skip to main content

What does the SELECT command do in SQL?

The SELECT command in SQL is used to retrieve data from one or several tables. It lets you pick specific fields, filter records, sort, and combine data.

Syntax:

sql
SELECT Field1, Field2, ... FROM Table_Name WHERE Condition ORDER BY Field LIMIT N;

Example:

sql
SELECT Name, Age FROM Employees WHERE DepartmentID = 101 ORDER BY Age DESC;

What this query does

  1. SELECT Name, Age, selects only these columns.
  2. FROM Employees, from the Employees table.
  3. WHERE DepartmentID = 101, only employees from department 101.
  4. ORDER BY Age DESC, sorts by age, descending.

Notes:

  • Every field can be selected at once: SELECT * FROM Employees;
  • Aggregate functions can be used: COUNT(), SUM(), AVG()
  • Tables can be combined via JOIN

Put simply, SELECT is the tool for getting the information you need out of a database, based on given conditions.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.