Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 02 / Topic 1 of 9

SELECT and FROM

SELECT * FROM table returns every column of every row:

SELECT * FROM suppliers;
 supplier_id |     name     | country 
-------------+--------------+---------
           1 | TechSource   | India
           2 | PageTurners  | UK
           3 | HomeGoods Co | Germany
(3 rows)

Usually you want specific columns — name them, in the order you want them back:

SELECT name, price FROM products;
        name        |  price  
--------------------+---------
 Laptop Pro 14      | 1200.00
 Laptop Air 13      |  950.00
 Phone X            |  799.00
 Phone Lite         |  399.00
 SQL for Beginners  |   35.00
 Postgres Deep Dive |   55.00
 Chef Knife         |   80.00
 Coffee Maker       |  120.00
 Desk Lamp          |   45.00
 USB-C Cable        |   15.00
(10 rows)

* is fine for poking around in psql. In application code, name the columns: explicit queries don't break when the table grows a column, and they don't drag unneeded data across the network.

🧪 Quick quiz — answer from memory, then check.

  1. What does * mean in SELECT *?
  2. Why name columns instead of * in application code?
Show the answers
  1. Every column of the table, in the table's own column order.
  2. The query keeps working (and keeps the same shape) when the table changes, and you don't fetch data you don't need.

Done here? The practice set for Part 2 — 8 exercises with solutions — is on the part page.

Search the guide