Anatomy of a query
Most SQL queries in this course use the same basic skeleton.
The slide deck introduces these core commands:
SELECT: chooses the columns you want.FROM: points to the table.WHERE: filters rows.GROUP BY: groups rows across values in a column.HAVING: filters groups.ORDER BY: sorts the results.LIMIT: restricts how many rows return.
In Module 4, focus on the three pieces that make a starter query work:
SELECT * FROM `project.dataset.table` LIMIT 100;
Think of it as three questions:
- What do I want?
SELECT *means "give me all columns." - Where does it live?
FROMpoints to the table path. - How many rows will I tolerate?
LIMIT 100returns only the first 100 rows.
LIMIT is a safety habit. It helps you test the shape of the data without returning too many rows at once.
The asterisk * means "all columns." It is helpful for a first look, but you should move toward naming the specific columns you need.
Learner action
Write a starter query against your selected table:
SELECT * FROM `[your_project].[your_dataset].[your_table]` LIMIT 100;
Almost every SQL query you'll ever write has the same skeleton. From Rosario's SQL 101 deck, the basic commands you'll use in this course are:
| Clause | What it does | Covered in |
|---|---|---|
SELECT | Picks the columns you want. | Module 4 ← you are here |
FROM | Points to the table. | Module 4 |
WHERE | Filters on rows. | Module 5 |
GROUP BY | Aggregates across values of a column. | Module 6 |
HAVING | Filters groups. | Module 6 |
ORDER BY | Sorts the results. | Module 5 |
LIMIT | Returns just the first N rows. | Module 4 |
Today we focus on the three required ones. Here's the simplest valid BigQuery query:
From the deck : three questions to chew on
Before you run your first query, answer these in your head:
- What does the
*mean? - What does
FROMdo? - What does
LIMITdo?
Plain English read-out: "Select every column from this table, but only show me the first 100 rows." When you previewed a table in Module 3, BigQuery was running this exact query for you behind the scenes.
Every SELECT has the same skeleton: SELECT … FROM …. The columns you list after SELECT come out in that exact order. Try it.
Action: Read the query out loud in your own words. Then continue.