Skip to Content
Learning Google BigQuery
book

Learning Google BigQuery

by Thirukkumaran Haridass, Eric Brown
December 2017
Beginner to intermediate
264 pages
5h 38m
English
Packt Publishing
Content preview from Learning Google BigQuery

DISTINCT

The legacy SQL does not support DISTINCT. The workaround is to use the group by statement, as shown in the following query. It outputs two columns: one is the column with distinct values and second is the count of those distinct values:

#legacySQLSELECT payment_type, count(1) FROM [bigquery-public-data:chicago_taxi_trips.taxi_trips] GROUP BY payment_typeORDER BY payment_type

Standard SQL supports the DISTINCT clause and it can be used as shown here. This query returns only one column as output:

#standardSQLSELECT DISTINCT payment_typeFROM `bigquery-public-data.chicago_taxi_trips.taxi_trips`ORDER BY payment_type
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Google BigQuery: The Definitive Guide

Google BigQuery: The Definitive Guide

Valliappa Lakshmanan, Jordan Tigani
Google BigQuery Analytics

Google BigQuery Analytics

Siddartha Naidu, Jordan Tigani

Publisher Resources

ISBN: 9781787288591Supplemental Content