SQL SELECT Statement
📘 SQL SELECT Statement
The SELECT statement is the most commonly used SQL command. It is used to retrieve data from one or more tables in a relational database.
1. Basic Syntax
-
SELECT— specifies the columns to fetch -
FROM— specifies the table to query
Example
2. Selecting All Columns
✔ Good for quick inspection
✖ Avoid in production (returns unnecessary data)
3. Using WHERE to Filter Results
Filtering supports operators such as:
-
=equal -
!=or<>not equal -
><>=<= -
BETWEEN -
LIKE -
IN
Example:
4. Sorting Results with ORDER BY
-
ASC→ ascending -
DESC→ descending
5. Renaming Columns with AS (Aliases)
6. Removing Duplicates with DISTINCT
7. Limiting Results (LIMIT / TOP)
PostgreSQL / MySQL / SQLite
SQL Server
8. Using Functions in SELECT
SQL allows functions inside the SELECT list:
-
COUNT() -
AVG() -
SUM() -
MIN() -
MAX()
Example:
