Intro to SQLfor Organizing
Subsection 4.1

Anatomy of a query

~4 min

Reading

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? FROM points to the table path.
  • How many rows will I tolerate? LIMIT 100 returns 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:

ClauseWhat it doesCovered in
SELECTPicks the columns you want.Module 4 ← you are here
FROMPoints to the table.Module 4
WHEREFilters on rows.Module 5
GROUP BYAggregates across values of a column.Module 6
HAVINGFilters groups.Module 6
ORDER BYSorts the results.Module 5
LIMITReturns just the first N rows.Module 4

Today we focus on the three required ones. Here's the simplest valid BigQuery query:

SELECT * FROM `project.dataset.table` LIMIT 100; columns table path row limit
Diagram 4.1 · The basic shape. Three pieces: what you want, where it lives, how many rows you'll tolerate. Every other clause is optional in this course.

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 FROM do?
  • What does LIMIT do?

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.