SQL SELECT

SELECT is the statement you will write more than any other in SQL. It reads data from one or more tables and returns it as a result table. Every report, dashboard and analysis starts with a SELECT.

A SELECT has two required parts: the list of columns you want, and the table they come from (FROM). Everything else (filtering, sorting, grouping) is added on top of this.

Syntax

SELECT column1, column2
FROM table_name;

Try it yourself

Run the example below on a real PostgreSQL database, then change it and run it again. Nothing to install, no sign-up.

select.sql · PostgreSQL
Loading editor…

Examples

1. Select specific columns

SELECT name, price FROM products;

Returns two columns for every row in products.

2. Select all columns

SELECT * FROM departments;

The asterisk means every column. Handy for exploring, but name your columns in real queries.

3. Calculate a new column

SELECT name, price, price * 0.9 AS sale_price FROM products;

You can do arithmetic in the SELECT list and name the result with AS.

Common mistakes

  • Forgetting the comma between column names: SELECT name price treats price as an alias for name.
  • Using SELECT * in production queries. It breaks when columns are added and transfers data you don't need.
  • Putting text values in double quotes. In PostgreSQL, double quotes are for column names; text uses single quotes.

Practice: test yourself

This challenge is from our interactive course. Write the query and press Check answer.

Challenge · 10 pts

Return only the name and price of all products.

challenge.sql · PostgreSQL
Loading editor…

FAQ

Does SQL care about upper or lower case?

Keywords like SELECT and FROM are case-insensitive, so select works too. Writing keywords in capitals is a convention that makes queries easier to read.

Do I need a semicolon at the end?

A semicolon ends a statement. Many tools accept a single statement without one, but it is good practice to always add it.

Learn SQL step by step

65 hands-on exercises, streaks, a leaderboard and a certificate.

Start free →