Raymond Raymond / Code Snippets & Tips

BigQuery SQL - SELECT * EXCEPT Clause

event 2021-03-13 visibility 10,049 comment 0 insights toc
insights Stats

As a data analyst, it is always a good practice to only select required columns instead of select all columns (SELECT *). This is even more important when querying systems like BigQuery which charges based on the amount of data read from storage for each query (Analysis Pricing).

However, sometimes it comes to handy if you only want to exclude certain columns from the result set. To do this, BigQuery provides an EXCEPT clause. This saves time to type the long list of column names in a SELECT statement.


The following code snippet select all the columns except column CustomerID from dim_customer table.

  * EXCEPT (CustomerID)

The output looks similar to the following screenshot:


Exclude multiple columns

We can also exclude multiple columns in EXCEPT clause:

  * EXCEPT (IsCurrent, StartDate, EndDate)

The result won't include column IsCurrent, StartDate and EndDate.

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts