Back to Chapters
Chapter Progress: 0 %0 / 6 Lessons Read
›

1. SQL basics: ask a table a question

1.1 SELECT and FROM: pick the columns you want

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      SQL is the language for asking a database questions. Data engineers use it every day, because company data lives in tables inside databases and warehouses such as BigQuery, Snowflake, Redshift and Databricks.

      • A table is like one Excel sheet
      • A row is one record, for example one customer
      • A column is one field, for example city

      The smallest query has two parts: SELECT names the columns you want and FROM names the table. SELECT * means every column. A query ends with a semicolon ;.

      pandas vs SQL

      • df[["name", "city"]] → SELECT name, city FROM customers
      • df → SELECT * FROM customers
      • A DataFrame → a table
      Must Know:

      Ask only for the columns you need. On big warehouse tables, SELECT * reads far more data, so the query is slower and can cost more.

      How it fits together

      1. Table: customers
      2. SELECT name, city
      3. Result: only 2 columns

      Watch the query run

      You write SELECT first, but the database reads FROM first.

      SQL

      SELECT name, cityFROM customers;

      Rows at this step

      name  | city
      ------+------
      Asha  | Noida
      Ravi  | Delhi
      Meera | Pune
      Kabir | Noida
      Zoya  | NULL

      Practice in SQL

      Show the product and amount columns of the orders table.

      Tables you can query: customers, orders
      customers
      id | name  | city
      ---+-------+------
      1  | Asha  | Noida
      2  | Ravi  | Delhi
      3  | Meera | Pune
      4  | Kabir | Noida
      5  | Zoya  | NULL
      
      orders
      id  | customer_id | product  | amount | status    | order_date
      ----+-------------+----------+--------+-----------+-----------
      101 | 1           | Laptop   | 55000  | delivered | 2026-01-05
      102 | 2           | Mouse    | 700    | delivered | 2026-01-06
      103 | 1           | Keyboard | 1500   | delivered | 2026-01-09
      104 | 3           | Monitor  | 12000  | cancelled | 2026-01-12
      105 | 2           | Laptop   | 52000  | delivered | 2026-01-15
      106 | 4           | Mouse    | 650    | pending   | 2026-01-18
      107 | 1           | Monitor  | 11500  | delivered | 2026-01-20
      108 | 3           | Keyboard | NULL   | pending   | 2026-01-22
      Expected output
      product  | amount
      ---------+-------
      Laptop   | 55000
      Mouse    | 700
      Keyboard | 1500
      Monitor  | 12000
      Laptop   | 52000
      Mouse    | 650
      Monitor  | 11500
      Keyboard | NULL

      Reference solution
      SELECT product, amount
      FROM orders;

      Question 1 · Easy

      Which keyword names the table to read?

      Question 2 · Medium

      What does SELECT * FROM orders return?

      Question 3 · Hard

      Why do data engineers avoid SELECT * on very large tables?

      Key takeaways

      SELECT picks columns and FROM picks the table. The database reads FROM first. Ask only for the columns you need.

      Lesson 1 of 24

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      SELECT and FROM: pick the columns you want
      Save your progress free for 1 month. Start free · Log in