Skip to content
C

SELECT


SELECT

Definition

SELECT retrieves data from one or more tables — it's the single most-used SQL statement, and the entry point for reading anything back out of a database.

How It Works

Running example — a products(id, name, category, price, stock) table, where stock can be NULL (not yet counted):

idnamecategorypricestock
1ProLaptopElectronics8500012
2NotebookStationery40NULL
3Python BasicsBooks3505
4ProPhoneElectronics450000
sql
SELECT name, price FROM products; SELECT * FROM products; -- every column SELECT name, price * 1.18 AS price_with_tax FROM products; -- computed expression

SELECT can return literal columns, computed expressions, or * (every column). The column list can also include arithmetic, string concatenation, or function calls — anything that produces one value per row.

Edge Cases and Pitfalls

  • SELECT * is convenient for exploring data interactively but risky in application code: it silently changes shape if the table's columns change later, and returns more data over the network than might be needed.
  • The order of columns in the output exactly matches the order written in the SELECT list — it has nothing to do with the table's physical column order.
  • SELECT alone with no FROM is valid in some dialects for evaluating a plain expression (SELECT 2 + 2;) — useful for testing an expression without touching any table.

Key Takeaways

  • SELECT column_list FROM table is the basic shape of every read query.
  • The column list can include real columns, computed expressions, and aliases.
  • Prefer explicit column lists over SELECT * in real application code.

Mock Test

  • SELECT - Quick Test

    8 questions on SELECT.

    8 questions · 8 min · Medium
    Start Mock Test