{"id":43596,"date":"2023-08-16T22:40:14","date_gmt":"2023-08-16T20:40:14","guid":{"rendered":"https:\/\/blog.sheetgo.com\/?p=43596"},"modified":"2025-12-17T18:44:03","modified_gmt":"2025-12-17T17:44:03","slug":"sintaxis-de-bigquery","status":"publish","type":"post","link":"https:\/\/www.sheetgo.com\/es\/blog\/data-science\/bigquery-syntax\/","title":{"rendered":"Sintaxis de BigQuery"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221; da_is_popup=&#8221;off&#8221; da_exit_intent=&#8221;off&#8221; da_has_close=&#8221;on&#8221; da_alt_close=&#8221;off&#8221; da_dark_close=&#8221;off&#8221; da_not_modal=&#8221;on&#8221; da_is_singular=&#8221;off&#8221; da_with_loader=&#8221;off&#8221; da_has_shadow=&#8221;on&#8221; da_disable_devices=&#8221;off|off|off&#8221;][et_pb_row _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><a href=\"https:\/\/cloud.google.com\/bigquery\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">BigQuery<\/span><\/a><span style=\"font-weight: 400;\"> is Google\u2019s fully-managed and serverless data warehouse that allows businesses to store and handle large amounts of data without having to invest in infrastructure. In order to retrieve data from BigQuery, they can use SQL syntax to run queries.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this article, you&#8217;ll find an easy guide to the BigQuery SQL syntax and learn how to write your first SQL queries.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;syntax&#8221; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<h2><span style=\"font-weight: 400;\">BigQuery SQL Syntax<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">SQL syntax refers to the language rules that you need to follow when writing SQL queries. Whenever you write a statement, you&#8217;ll use keywords such as SELECT, FROM, WHERE, and ORDER BY.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; background_color=&#8221;rgba(240,232,255,0.73)&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">Note: In order to improve readability, we&#8217;ll follow some best practices to write SQL queries.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1) We&#8217;ll use uppercase to distinguish between keywords and tables or columns. Therefore, we&#8217;ll capitalize keywords but we&#8217;ll use lowercase for all tables and columns.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2) Although we can write multiple statements into the same line, we&#8217;ll separate statements using new lines.\u00a0<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">If you want to get started with BigQuery, you&#8217;ll find a quick-start guide to SQL syntax below.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;select&#8221; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<h3><span style=\"font-weight: 400;\">SELECT<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We&#8217;ll use the SELECT statement to select the columns the query will return.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><b>SELECT Syntax<\/b><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT column1, column2, &#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM table_name;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">In this example, we&#8217;ll show you how to use SQL queries to retrieve data from an NCAA basketball dataset.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, we&#8217;ll execute a SQL query to select three columns &#8211; school_ncaa, name, and alias &#8211; from this dataset.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After the SELECT statement, add all the columns you want to select, separated by commas. The FROM clause specifies the table we are querying to retrieve the data.\u00a0<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT school_ncaa, name, alias\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams` ;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-1.png&#8221; alt=&#8221;bigquery syntax 1&#8243; title_text=&#8221;bigquery syntax 1&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">This query has returned rows with the following columns:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">school_ncaa &#8211; This column contains the school name associated with each team.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">name &#8211; This column has the team name for each row.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">alias &#8211; This column contains common aliases or abbreviated names used for some teams.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">As you can see, it has returned all the data I&#8217;ve requested split into columns.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this example, I&#8217;ve asked BigQuery to return data from these three columns. If you want to select all columns from the dataset, use an asterisk (*) instead.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT *\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams` ;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-2.png&#8221; alt=&#8221;bigquery syntax 2&#8243; title_text=&#8221;bigquery syntax 2&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text module_id=&#8221;where&#8221; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<h3><span style=\"font-weight: 400;\">WHERE<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We&#8217;ll use the WHERE clause to filter data from the dataset.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><b>WHERE Syntax<\/b><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT column1, column2, &#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM table_name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE condition;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s say I want to retrieve data from all the columns but only for the rows where the name column equals &#8216;Crimson&#8217;.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So let&#8217;s break down the formula:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">SELECT * &#8211; This specifies we want all columns returned. The * selects every column.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM bigquery-public-data.ncaa_basketball.mbb_teams &#8211; This specifies the table we are querying, the mbb_teams table.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Crimson&#8217; &#8211; This WHERE clause filters the rows to only those where the name column value equals &#8216;Crimson&#8217;.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT *\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Crimson&#8217;;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-3.png&#8221; alt=&#8221;bigquery syntax 3&#8243; title_text=&#8221;bigquery syntax 3&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">This BigQuery SQL query has returned all columns for rows from the mbb_teams table where the name column equals &#8216;Crimson&#8217;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now I&#8217;ll use the OR condition because I want BigQuery to retrieve rows that match either &#8216;Crimson&#8217; or &#8216;Tigers&#8217; team names. I&#8217;ll add an OR condition to the WHERE clause. <\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Crimson&#8217; OR name = &#8216;Tigers&#8217;;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-4.png&#8221; alt=&#8221;bigquery syntax 4&#8243; title_text=&#8221;bigquery syntax 4&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">Now BigQuery has returned data for rows where the name is either &#8216;Crimson&#8217; or &#8216;Tigers&#8217;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If I want to return multiple values with a WHERE clause, I can add an IN condition to the formula. When I add IN to the WHERE statement, BigQuery will return all the values in brackets.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name IN (&#8216;Crimson&#8217;,&#8217;Tigers&#8217;,&#8217;Gators&#8217;);<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-5.png&#8221; alt=&#8221;bigquery syntax 5&#8243; title_text=&#8221;bigquery syntax 5&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">If you want to add multiple filters or multiple criteria to be met in the query results, you should use the AND condition. The AND condition will return values only when both conditions are satisfied.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this example, I want BigQuery to return values only for these teams: Auburn Tigers or Clemson Tigers. Therefore, both criteria must be met. The name should be &#8220;Tigers&#8221;, and the school should be Auburn or Clemson. Here&#8217;s the formula I&#8217;ll use:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Tigers&#8217; AND school_ncaa = &#8216;Auburn&#8217; OR school_ncaa = &#8216;Clemson&#8217;;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-6.png&#8221; alt=&#8221;bigquery syntax 6&#8243; title_text=&#8221;bigquery syntax 6&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">Now let&#8217;s say I want BigQuery to filter rows where the name starts with &#8216;A&#8217;. Unlike the previous examples, when I used the WHERE statement to return exact values, here I&#8217;ll use the LIKE operator for partial string matching. Here&#8217;s how I can use the LIKE command:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name LIKE &#8216;A%&#8217;;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-7.png&#8221; alt=&#8221;bigquery syntax 7&#8243; title_text=&#8221;bigquery syntax 7&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">These are some examples of how you can use the LIKE command to filter data based on specific criteria.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p><b>LIKE\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p><b>Result<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><span style=\"font-weight: 400;\">LIKE &#8216;a%&#8217;<\/span><\/p>\n<\/td>\n<td>\n<p><span style=\"font-weight: 400;\">Returns values that start with &#8220;a&#8221;<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><span style=\"font-weight: 400;\">LIKE &#8216;%a&#8217;<\/span><\/p>\n<\/td>\n<td>\n<p><span style=\"font-weight: 400;\">Returns values that end with &#8220;a&#8221;<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><span style=\"font-weight: 400;\">LIKE &#8216;%ty%&#8217;<\/span><\/p>\n<\/td>\n<td>\n<p><span style=\"font-weight: 400;\">Returns values that have &#8220;ty&#8221; in any position<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><span style=\"font-weight: 400;\">LIKE &#8216;_s%&#8217;<\/span><\/p>\n<\/td>\n<td>\n<p><span style=\"font-weight: 400;\">Returns values that have &#8220;s&#8221; in the second position<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><span style=\"font-weight: 400;\">LIKE &#8216;a%s&#8217;<\/span><\/p>\n<\/td>\n<td>\n<p><span style=\"font-weight: 400;\">Returns values that start with &#8220;a&#8221; and ends with &#8220;s&#8221;<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">If I want BigQuery to filter rows where the name starts with &#8216;A&#8217;, but exclude names starting with &#8216;Ag&#8217;, I can add a NOT LIKE command.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name LIKE &#8216;A%&#8217; AND name NOT LIKE &#8216;Ag%&#8217;;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-8.png&#8221; alt=&#8221;bigquery syntax 8&#8243; title_text=&#8221;bigquery syntax 8&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text module_id=&#8221;order&#8221; _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<h3><span style=\"font-weight: 400;\">ORDER BY<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The ORDER BY statement is used to sort values from a specific column in ascending or descending order.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><b>ORDER BY syntax<\/b><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT column1, column2, &#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM table_name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ORDER BY column1, column2, &#8230; ASC|DESC;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">I&#8217;ll write a query to retrieve data filtered by a specific team name and order the results by school in ascending order. When I order results in ascending order, the ASC condition is optional.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Tigers&#8217;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ORDER BY school_ncaa;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-9.png&#8221; alt=&#8221;bigquery syntax 9&#8243; title_text=&#8221;bigquery syntax 9&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.21.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">As you can see, BigQuery has sorted the school names alphabetically. If I add the DESC condition, it will sort the school names in descending order.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text module_class=&#8221;spreadsheet-function&#8221; _builder_version=&#8221;4.21.2&#8243; border_width_left=&#8221;4px&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">SELECT alias, school_ncaa, name, market<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FROM `bigquery-public-data.ncaa_basketball.mbb_teams`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WHERE name = &#8216;Tigers&#8217;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ORDER BY school_ncaa DESC;<\/span><\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/static.sheetgo.com\/wp-content\/uploads\/2023\/08\/bigquery-syntax-10.png&#8221; alt=&#8221;bigquery syntax 10&#8243; title_text=&#8221;bigquery syntax 10&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.22.2&#8243; _module_preset=&#8221;default&#8221; width=&#8221;100%&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][\/et_pb_image][et_pb_text module_id=&#8221;connect&#8221; _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;]<\/p>\n<h2><span style=\"font-weight: 400;\">How to connect BigQuery to Google Sheets<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">There you have it! That&#8217;s how you can write your first queries using SQL in BigQuery. If you&#8217;re a spreadsheet user, check out this article on <\/span><a href=\"https:\/\/www.sheetgo.com\/blog\/how-to-solve-with-sheetgo\/how-to-get-data-from-bigquery-to-google-sheets-automatically\/\">getting data from BigQuery to Google Sheets automatically.<\/a><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BigQuery is Google\u2019s fully-managed and serverless data warehouse that allows businesses to store and handle large amounts of data without having to invest in infrastructure. In order to retrieve data from BigQuery, they can use SQL syntax to run queries. In this article, you&#8217;ll find an easy guide to the BigQuery SQL syntax and learn [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":43843,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[31],"tags":[],"class_list":["post-43596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/posts\/43596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/comments?post=43596"}],"version-history":[{"count":0,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/posts\/43596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/media\/43843"}],"wp:attachment":[{"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/media?parent=43596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/categories?post=43596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sheetgo.com\/es\/wp-json\/wp\/v2\/tags?post=43596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}