How to Run Your First BigQuery Query (Console + bq CLI)

By the end of this page you will run a real SQL query in the BigQuery console, run the same query from the bq command-line tool, and understand what “bytes scanned” means for your bill. Everything here uses free public datasets, so you can follow along without spending anything.

BigQuery is one of the fastest ways to query large datasets on GCP. The BigQuery Overview covers what it is and when to use it. This page is purely practical: open a query editor, paste SQL, see results.

Simple explanation

BigQuery is a serverless data warehouse. You do not manage servers, install software, or create indexes. You write a SQL query, BigQuery fans the work across thousands of machines, and results come back in seconds.

”Running a query” means: you send SQL to BigQuery, it reads only the columns your query references from its columnar storage, processes the data, and returns the result. You pay based on how many bytes it read, not how long it took or how many rows came back.

Analogy

Think of BigQuery like a library research service. You hand in a question (your SQL), a team of researchers fans out across the shelves (columnar storage), and they only pull the specific books (columns) your question requires. You are charged based on how many books they pulled off the shelves, not how long they spent reading or how many answers they wrote down for you.

What you will do

  • Run a SQL query against a public dataset in the BigQuery console
  • Read the bytes-scanned counter and understand what it means
  • Run the same query from the bq CLI
  • Run a dry run to estimate cost before executing
  • See why SELECT * costs more than selecting specific columns
  • Learn why LIMIT does not reduce bytes scanned

Before you start

Open the BigQuery console. Go to console.cloud.google.com/bigquery. Make sure the correct project is selected in the project dropdown at the top of the page. If you are not sure how the Cloud Console works, read that page first.

Billing is optional for this walkthrough. BigQuery has a sandbox mode that works without a billing account. You get 1 TB of free query processing per month and can query any public dataset. The sandbox restricts some features (no streaming inserts, tables expire after 60 days), but everything on this page works in the sandbox. See the GCP Free Tier page for the full breakdown.

Public datasets. BigQuery hosts hundreds of datasets under the bigquery-public-data project. To browse them, click + Add in the Explorer panel, then select Public datasets. The queries on this page use the bigquery-public-data.usa_names.usa_1910_2013 table, a small dataset of baby names by year and state.

For CLI steps: Cloud Shell vs local install. The bq tool comes pre-installed in Cloud Shell, which you can open from any browser with no setup.

Local bq requires real setup

If you want to run bq on your own machine, you need to install the Google Cloud CLI, run gcloud init, and authenticate with gcloud auth login. That is not a one-click process. For your first query, use Cloud Shell instead.

Run your first query in the BigQuery console

Step 1. Open the BigQuery console and click + Compose a new query (or use the SQL editor that is already open).

Step 2. Paste this query into the editor:

SELECT
  name,
  SUM(number) AS total
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'TX'
GROUP BY name
ORDER BY total DESC
LIMIT 10;

This finds the 10 most popular baby names in Texas across all years in the dataset. The table is small (about 6 MB), so this query is well within free-tier limits.

Step 3. Before clicking Run, look at the bottom-right corner of the editor. The query validator shows a green checkmark and an estimate like “This query will process 51.3 MB when run.” That estimate is your built-in cost preview.

Step 4. Click Run. Results appear in the panel below within a few seconds.

Step 5. Click the Job information tab above the results. This shows bytes processed, bytes billed, slot time used, and whether the result came from cache. Check this after every query. It is the fastest way to build cost intuition.

Tip: Preview before you query

The Preview button on any table in the Explorer panel shows sample rows for free, with zero bytes scanned. Use Preview to inspect a table’s shape before writing a query against it. Preview reads from stored metadata and does not execute SQL.

Run the same idea with the bq CLI

Open Cloud Shell from the console (the terminal icon in the top-right toolbar), or use a local terminal where you have the gcloud CLI installed and authenticated.

Run the query:

bq query \
  --use_legacy_sql=false \
  'SELECT name, SUM(number) AS total
   FROM `bigquery-public-data.usa_names.usa_1910_2013`
   WHERE state = "TX"
   GROUP BY name
   ORDER BY total DESC
   LIMIT 10'

The —use_legacy_sql=false flag tells bq to use GoogleSQL (standard SQL). Without it, bq defaults to legacy SQL, which is an older dialect that does not support modern features like WITH clauses, STRUCT, or ARRAY. Always include this flag.

Run a dry run first:

bq query \
  --use_legacy_sql=false \
  --dry_run \
  'SELECT name, SUM(number) AS total
   FROM `bigquery-public-data.usa_names.usa_1910_2013`
   WHERE state = "TX"
   GROUP BY name
   ORDER BY total DESC
   LIMIT 10'

A dry run validates the SQL and prints the estimated bytes that would be scanned. It does not execute the query or use any quota. The output looks like:

Query successfully validated. Assuming the tables are not modified,
running this query will process 51361861 bytes of data.

Run a dry run before executing any query on a table whose size you do not know. It is free and takes less than a second.

Note

If you want to avoid typing —use_legacy_sql=false every time, add this line to a file called ~/.bigqueryrc:

--use_legacy_sql=false

How BigQuery decides cost and performance

Bytes scanned is the core cost metric. On on-demand pricing, you pay per byte scanned. The current rate is $6.25 per TB after the first free 1 TB each month. The query itself can take 2 seconds or 20 seconds. The cost is the same if both queries scan the same bytes.

Why SELECT * is expensive. BigQuery uses columnar storage. It only reads the columns your query actually references. SELECT * forces it to read every column in the table. On a 50-column table where you only need 3 columns, SELECT * scans roughly 17 times more data. Always name the columns you need.

Common misconception: LIMIT does not reduce cost

LIMIT 10 tells BigQuery to return only 10 rows after it finishes scanning. The scan itself is unchanged. A query with LIMIT 10 and the same query without LIMIT scan exactly the same amount of data. To actually scan less, select fewer columns or add partition filters.

Dry runs show cost before you spend anything. In the console, the validator shows estimated bytes as you type. In the CLI, the —dry_run flag does the same thing. Use both. There is no reason to guess what a query will cost.

Cached results are free. BigQuery caches query results for 24 hours. If you run the exact same query on unchanged data, the second run is free and returns instantly. The cache is per-user. Changing even a single space in the SQL invalidates the cache.

Try this experiment

In the console, paste SELECT * FROM bigquery-public-data.usa_names.usa_1910_2013 LIMIT 5 and note the bytes estimate. Then change it to SELECT name, number FROM bigquery-public-data.usa_names.usa_1910_2013 LIMIT 5. The bytes drop significantly, even though both queries return only 5 rows. That is columnar storage at work.

Console vs bq CLI

BigQuery consolebq CLI
Best forLearning, exploring data, visual debuggingScripting, automation, CI/CD pipelines
SetupNone. Browser onlyCloud Shell: none. Local: install gcloud CLI + authenticate
Cost estimateLive validator shows bytes as you type—dry_run flag
ResultsVisual table, export to CSV/SheetsText table in terminal, or —destination_table to save
Schema browsingExplorer panel with table previewsbq show and bq ls commands
RepeatabilityManual (copy/paste or saved queries)Scriptable (version control, cron, pipelines)

Cloud Shell is the easiest bridge between the two. It gives you a terminal with bq pre-installed and pre-authenticated, directly inside the console. No local install, no authentication steps. Start there if you want to try the CLI without any setup.

When to use this

  • You are new to BigQuery and want to see how it works before reading about architecture or pricing theory.
  • You want to explore a public dataset before deciding whether to load your own data.
  • You need to run a quick ad-hoc query on data that already exists in BigQuery: checking row counts, sampling values, or verifying a load.
  • You are evaluating BigQuery vs another tool like Cloud SQL and want to feel the difference between an analytical warehouse and a transactional database.
  • You are building a script or pipeline and need to validate that your SQL works before automating it with the bq CLI.

Common beginner mistakes

  1. Assuming LIMIT reduces cost. This is the most common BigQuery misconception. LIMIT 10 does not reduce bytes scanned. It only limits how many rows are returned after the full scan. To reduce cost, select fewer columns and use partition filters.
  2. Using SELECT * on unfamiliar tables. On a wide table, SELECT * can scan 10–20x more data than selecting the columns you need. Always name your columns. Use the Preview button or bq show to check the schema first.
  3. Forgetting project or dataset context. In the CLI, if you do not specify —project_id, bq uses your default project. In the console, check the project selector at the top. Querying the wrong project means unexpected billing or “not found” errors.
  4. Skipping dry runs. Running a query on a table whose size you have not checked is how surprise bills happen. Use —dry_run in the CLI or read the validator estimate in the console before executing. If you see a number in the hundreds of GB, stop and rethink. See BigQuery Query Too Large for what to do when a query scans more than expected.
  5. Using local bq without proper setup. The bq tool requires the Google Cloud CLI to be installed, initialized (gcloud init), and authenticated (gcloud auth login). If you skip any of those steps, you will get authentication errors. Cloud Shell avoids all of this.
  6. Confusing Preview with a query. The Preview button shows cached sample rows for free. It does not execute SQL and does not support filtering or aggregation. If you need to filter or aggregate, you need to run a query.
  7. Forgetting —use_legacy_sql=false in the CLI. The bq tool defaults to legacy SQL. Modern features like WITH clauses, STRUCT, ARRAY, and window functions require GoogleSQL (standard SQL). Always include the flag or set it in ~/.bigqueryrc.

Common errors and quick fixes

ErrorCauseFix
Access Denied: Project my-project: User does not have bigquery.jobs.create permissionYour account lacks the BigQuery Job User role on the projectAsk a project admin to grant you roles/bigquery.jobUser, or switch to a project where you have access
Not found: Table bigquery-public-data:dataset.tableWrong table name, or legacy SQL syntax is being used for the table referenceCheck the exact table path in the Explorer panel. Use backtick-quoted names with dots: bigquery-public-data.usa_names.usa_1910_2013
BigQuery API has not been enabled for projectThe BigQuery API is disabled in your projectGo to APIs & Services > Enable APIs in the console and enable the BigQuery API
Cannot read and write in different locationsYour query references tables in different regions, or your destination table is in a different region than the sourceMake sure all tables in a query are in the same region. Set —location in the CLI if needed
Syntax error on a WITH clause or STRUCTLegacy SQL is active. It does not support modern syntaxAdd —use_legacy_sql=false in the CLI, or confirm “GoogleSQL” is selected in the console editor settings

Frequently asked questions

Do I need billing to run a BigQuery query?

Not necessarily. The BigQuery sandbox lets you query public datasets with no billing account attached. You get 1 TB of free query processing per month. Basic querying works without billing. If you need to load your own data, create scheduled queries, or use streaming inserts, you will need a billing account.

What is the BigQuery sandbox?

The BigQuery sandbox is a free tier that lets you use BigQuery without attaching a billing account to your project. You can query public datasets and load limited amounts of data. Tables in the sandbox expire after 60 days and some features like streaming inserts and DML are restricted, but it is the safest way to learn.

Does LIMIT reduce query cost in BigQuery?

No. LIMIT only restricts how many rows are returned after BigQuery has already scanned all qualifying data. A query with LIMIT 10 scans the same bytes as the same query without LIMIT. To reduce cost, select fewer columns and use partition filters.

What is a dry run in BigQuery?

A dry run validates your SQL and reports how many bytes it would scan, without executing the query or using any quota. In the bq CLI, add the --dry_run flag. In the console, the query validator shows estimated bytes automatically as you type. Use dry runs before running any large or unfamiliar query.

Should I use the BigQuery console or the bq CLI first?

Start with the console. It shows query validation, bytes estimates, and results visually, which makes it easier to learn how BigQuery works. Move to the bq CLI when you need to script queries, automate jobs, or work in environments without a browser.

Last verified: 26 March 2026 Cloud services change frequently. Verify details against official documentation before making infrastructure decisions.