SQL SELECT Statement

The SQL SELECT statement reads data from a database. It is the statement you will write most often, and every report, dashboard and search page in an application runs some form of SELECT behind the scenes.

The result of a SELECT is itself a small table, called the result set.

SELECT Specific Columns

List the columns you want after SELECT, separated by commas. Only those columns appear in the result, in the order you listed them.

SELECT ProductName, Category, Price
FROM Products;
ProductName    | Category   | Price
---------------+------------+------
Basmati Rice   | Grains     | 12.5
Green Tea      | Beverages  | 6
Olive Oil      | Oils       | 18.75
Dark Chocolate | Snacks     | 4.25
Coffee Beans   | Beverages  | 22
Almonds        | Snacks     | 15
Wheat Flour    | Grains     | 8
Honey          | Sweeteners | 11.5
(8 rows)

SELECT All Columns

SELECT * returns every column. It is handy while exploring, but in real applications name the columns you need: it is faster, and your code will not break when someone adds a column.

SELECT * FROM Orders;
OrderID | CustomerID | ProductID | Quantity | OrderDate
--------+------------+-----------+----------+-----------
101     | 1          | 1         | 10       | 2026-01-05
102     | 2          | 2         | 25       | 2026-01-09
103     | 3          | 5         | 4        | 2026-02-11
104     | 1          | 3         | 6        | 2026-02-14
105     | 5          | 4         | 40       | 2026-03-02
106     | 8          | 5         | 12       | 2026-03-20
107     | 2          | 6         | 8        | 2026-04-01
108     | 7          | 7         | 30       | 2026-04-18
109     | 9          | 2         | 15       | 2026-05-07
110     | 3          | 1         | 5        | 2026-05-22
(10 rows)

Column Aliases with AS

An alias gives a column a different name in the result. This is useful for readability and for calculated columns that would otherwise have an ugly name.

SELECT ProductName AS Product,
       Price AS UnitPrice
FROM Products;
Product        | UnitPrice
---------------+----------
Basmati Rice   | 12.5
Green Tea      | 6
Olive Oil      | 18.75
Dark Chocolate | 4.25
Coffee Beans   | 22
Almonds        | 15
Wheat Flour    | 8
Honey          | 11.5
(8 rows)

Calculated Columns

You can do arithmetic inside SELECT. Here we calculate the value of the stock on hand for each product by multiplying price by stock.

SELECT ProductName,
       Price * Stock AS StockValue
FROM Products;
ProductName    | StockValue
---------------+-----------
Basmati Rice   | 1500
Green Tea      | 1800
Olive Oil      | 843.75
Dark Chocolate | 2125
Coffee Beans   | 1760
Almonds        | 900
Wheat Flour    | 1600
Honey          | 0
(8 rows)

Joining Text Together

The || operator joins strings in SQLite, PostgreSQL and Oracle. In MySQL and SQL Server use CONCAT(a, b) instead (SQL Server also accepts +).

SELECT CustomerName || ' (' || City || ')' AS Customer
FROM Customers
LIMIT 3;
Customer
------------------------
Alpha Traders (Lahore)
Blue Sky Foods (Karachi)
Cedar Market (London)
(3 rows)

Frequently asked questions

Is SELECT * bad practice?

It is fine for quick exploration, but in application code it is better to list columns. You transfer less data and your query does not change behaviour when the table structure changes.

Can I use an alias without AS?

Yes, most databases accept SELECT Price UnitPrice. Writing AS is clearer, so it is recommended.

Does SELECT change the data in the table?

No. SELECT only reads data. To change data you use INSERT, UPDATE or DELETE.