SQL Select

The SELECT statement is used to retrieve data from one or more tables. Learn how to select columns, use expressions and aliases, and write readable queries.

On this page

SQL SELECT Statement

The SELECT statement is used to retrieve data from a database. It is the most common SQL command and the foundation for filtering, sorting, joining tables, and creating reports.

SELECT Syntax

SELECT column1, column2, ...
FROM table_name;

Select All Columns

To return all columns from a table, use *. This is useful for quick testing, but in real projects it is often better to select only the columns you need.

SELECT *
FROM customers;

Select Specific Columns

Selecting specific columns makes your queries faster to read, easier to maintain, and often more efficient.

SELECT name, email
FROM customers;

Return a Single Column

You can select a single column when you only need one piece of information.

SELECT email
FROM customers;

Rename Columns with Aliases

An alias gives a column a temporary name in the result set. Aliases are useful for readability and for computed columns.

SELECT name AS customer_name, email AS contact_email
FROM customers;

Select Computed Values

You can select expressions, not just stored columns. This is useful for calculations, formatting, and building derived values.

SELECT price, quantity, price * quantity AS total
FROM order_items;

Select a Constant Value

You can also select constant values, which can be useful in reports or for debugging.

SELECT 'active' AS status, name
FROM customers;

Handle NULL Values

NULL means “no value”. Expressions involving NULL often produce NULL. Many databases provide functions to replace NULL with a default value.

SELECT name, COALESCE(phone, 'N/A') AS phone
FROM customers;

Make Results Easier to Read

SQL ignores extra whitespace and line breaks, so you can format queries for clarity. A common style is to place each clause on a new line.

SELECT name, email
FROM customers
ORDER BY name;

Limit the Number of Rows

Some database systems use LIMIT (MySQL/MariaDB), while others use TOP (SQL Server). This tutorial will point out differences when needed.

SELECT name, email
FROM customers
LIMIT 10;

SELECT with Filtering and Sorting

Most SELECT queries become powerful when combined with filtering and sorting:

  • WHERE filters rows based on conditions
  • ORDER BY sorts the result set
SELECT name, email
FROM customers
WHERE country = 'USA'
ORDER BY name;

Common Mistakes

  • Using SELECT * in production queries when you only need a few columns
  • Forgetting to add WHERE when you expected filtered results
  • Not using aliases for computed columns, making results hard to read

Next Steps

Continue with SQL Select Distinct to learn how to return unique values, then move on to WHERE to filter your results.