SQL SELECT Statement: Retrieve and Filter Data

Last updated: August 27, 2026.

The SQL SELECT statement retrieves columns and rows from one or more tables. A clear query names the required columns, filters early, and specifies an order when presentation order matters.

Basic SELECT syntax

SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1;

Select specific columns

SELECT employee_id, first_name, last_name
FROM employees
ORDER BY last_name, first_name;

Listing columns explicitly documents the result shape and avoids transferring data the application does not need.

Filter rows

SELECT product_id, product_name, unit_price
FROM products
WHERE unit_price BETWEEN 25 AND 100
  AND discontinued = 0
ORDER BY unit_price DESC;

Join related tables

SELECT
    o.order_id,
    c.customer_name,
    o.order_date
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC, o.order_id DESC;

Return calculated values

SELECT
    product_name,
    unit_price * quantity AS line_total
FROM order_items
ORDER BY line_total DESC;

Use parameterized queries in application code instead of concatenating user input into SQL. For complete syntax and database-specific clauses, see the MySQL SELECT reference.

admin

admin

Leave a Reply

Your email address will not be published.