Ravindra BagaleCourses & study guides Track your progress

1. What Is SQL and Why Analysts Need It

1.3 Tables, Rows, Columns and Keys Explained for Beginners

Why. Wrong grain (what one row means) breaks every total later.

What. A table has columns (fields) and rows (records). A primary key uniquely names a row. A foreign key points to a key in another table.

How. In raja_coffee: customers.customer_id is a key. orders.customer_id points to it.

Steps

  1. Open customers — one row per person.
  2. Open orders — one row per order.
  3. Notice orders.customer_id links to customers.

Examples

Example 1 · dataset: raja_coffee

SELECT customer_id, name, city FROM customers ORDER BY customer_id LIMIT 4;

Output

customer_idnamecity
1Asha PatilPune
2Omar KhanMumbai
3Sofia MendesGoa
4James OkonkwoPune

Meaning. Each customer_id appears once — that is the key idea.

Ravindra Bagale's Tip

Before writing SQL, say out loud: One row in this table means ___.