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
SELECT Name, Age, selects only these columns.FROM Employees, from theEmployeestable.WHERE DepartmentID = 101, only employees from department 101.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,
SELECTis the tool for getting the information you need out of a database, based on given conditions.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.