Select

The SQL SELECT statement retrieves rows from one or more database tables, letting you choose exactly which columns and records you want returned.

Learn Python, JavaScript, Java and more with free interactive lessons, real projects and AI-powered help. Beginner-friendly.

Part of the free SQL course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll be able to pull exactly the data you want out of any table — choosing columns, renaming them, removing duplicates, paginating, and calculating new values on the fly. SELECT is the command you'll use more than any other in SQL.

Every query in this lesson runs against this little products table. Keep it in mind as you read — knowing the data is half of writing good SQL.

A SELECT statement answers the question "show me some data". The simplest version asks for everything:

SELECT is like ordering from a menu. SELECT * means "bring me one of everything"; SELECT product_name, price means "just the dish name and the price, please".

In real applications, name the columns you want instead of using * — it's faster, clearer, and won't silently change when the table gains new columns.

Fill in the blanks to list the category and stock of every product. The expected result is in the comments so you can check yourself.

The AS keyword gives a column a friendly name in the result. The underlying table is never changed — the alias only exists for this one query. It becomes essential the moment you start calculating columns.

DISTINCT collapses duplicate rows into one. Our table has three Electronics products, but asking for distinct categories returns each category only once.

One blank this time — add the keyword that removes duplicates.

LIMIT caps the number of rows returned; OFFSET skips rows first. Together they power "page 1, page 2, page 3" pagination you see on every website.

LIMIT 3 OFFSET 3 is "skip the first 3 results, then give me the next 3" — exactly page 2 of a 3-per-page list.

A SELECT can compute brand-new columns from existing ones using maths or functions. The original data stays untouched — the new column lives only in the result.

Q: Does the order of columns in SELECT matter?

Yes — the result shows columns in the exact order you list them. SELECT price, product_name puts price first.

Keywords ( SELECT , FROM ) are not — but it's convention to UPPERCASE them. Table and column names can be case-sensitive depending on the database, so match them exactly.

Readability and necessity: calculated columns have no name until you give them one, and clear headings make results far easier to read.

No. SELECT only reads — it never modifies the table. DISTINCT just de-duplicates the result .

Put it all together — a brief, a blank canvas, and the expected result in the comments. Write it, then copy it into a playground to confirm.

Practice quiz

What does the * wildcard mean in SELECT * FROM products;?

  • The first column only
  • All rows where a value is true
  • All columns
  • A calculated column

Answer: All columns. The * is a wildcard meaning 'all columns', so SELECT * returns every column.

What is the purpose of the AS keyword in a SELECT?

  • It renames a column only in the query's output
  • It permanently renames the column in the table
  • It removes duplicate rows
  • It sorts the result

Answer: It renames a column only in the query's output. AS gives a column an alias for the result only; the underlying table is unchanged.

What does SELECT DISTINCT category FROM products; return?

  • Every category value, with duplicates
  • The number of categories
  • Only the first category
  • Each distinct category value, once

Answer: Each distinct category value, once. DISTINCT collapses duplicate rows so each category appears only once.

What does LIMIT 3 do?

  • Skips the first 3 rows
  • Returns at most 3 rows
  • Returns exactly 3 columns
  • Sorts into 3 groups

Answer: Returns at most 3 rows. LIMIT caps the number of rows returned to at most the given number.

Which clause skips rows before returning results, used for pagination?

  • OFFSET
  • DISTINCT
  • AS
  • LIMIT only

Answer: OFFSET. OFFSET skips a number of rows first; combined with LIMIT it powers pagination.

In standard SQL, what surrounds a text value such as Electronics in a query?

  • Double quotes
  • Backticks
  • Single quotes
  • No quotes

Answer: Single quotes. Text/string literals are written in single quotes, e.g. 'Electronics'. Double quotes are for identifiers.

Does a calculated column like price * 1.20 AS price_with_tax change the table?

  • Yes, it updates every row
  • No, it only exists in the query result
  • Yes, but only the price column
  • It deletes the original column

Answer: No, it only exists in the query result. Calculated columns live only in the result; SELECT never modifies the table.

Which query correctly asks for only product_name and price?

  • SELECT product_name price FROM products;
  • SELECT (product_name, price) products;
  • FROM products SELECT product_name, price;
  • SELECT product_name, price FROM products;

Answer: SELECT product_name, price FROM products;. List the columns after SELECT separated by a comma, then the table after FROM.

Does the order of columns listed in SELECT affect the result?

  • No, columns always come back alphabetically
  • Yes, columns appear in the order you list them
  • No, order is random
  • Only if you use AS

Answer: Yes, columns appear in the order you list them. The result shows columns in the exact order you list them in the SELECT.

On which part of the data does DISTINCT decide a row is a duplicate?

  • Only the first selected column
  • The id column only
  • Every selected column together
  • Nothing — it removes random rows

Answer: Every selected column together. A row counts as a duplicate only if every selected column matches; DISTINCT works on the whole selected row.