Qualifying tables in query

The table name must be preceded by the dataset name if the query is being run against the current project or default project. If the query uses tables from other projects, then the project name must also be added to the qualifier. The following examples show how to qualify the tables in legacy SQL and standard SQL.

If the table being queried is located in the default project or currently selected project in the BigQuery console, then the project name is optional. In legacy SQL, the table and its qualifier are enclosed within []. In the following example, HumanResourceDS is the dataset name, and it is followed by the table name with a . between the dataset name and table name:

#legacySQL
SELECT Employee_ID, Employee_Joining_Date, Employee_Last_Name, Employee_First_Name, Employee_location
FROM [HumanResourceDS.employee_details]

In standard SQL, the table and its qualifier are enclosed within `` (backquote, which is located on the tilde operator key ~), as shown in this query:

#standardSQL
SELECT Employee_ID, Employee_Joining_Date, Employee_Last_Name, Employee_First_Name, Employee_location
FROM `HumanResourceDS.employee_details`

If the tables are in a project that is not the current or default project in BigQuery, then qualify the table with the project name and dataset name, as shown in the following query. It shows how to qualify a table in another project in legacy SQL mode. The project name and dataset name are separated by:

#legacySQL
SELECT company, payment_type, count(1)
FROM [bigquery-public-data:chicago_taxi_trips.taxi_trips]
GROUP BY company, payment_type
ORDER BY company, payment_type

The following query shows how to qualify the table in another project in standard SQL mode. The project name and the dataset name are separated by a . sign:

#standardSQL
SELECT company, payment_type, count(1)
FROM `bigquery-public-data.chicago_taxi_trips.taxi_trips`
GROUP BY company, payment_type
ORDER BY company, payment_type
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.231