rmg
rmg

Reputation: 1089

How to remove/avoid prepended tablename in bigquery?

GBQ prepends the table name on a join:

SELECT *
FROM dataset.table1 a
JOIN dataset.table2 b
  ON a.key_a = b.key_b

Will produce a table with fields named a_field_1, a_field_2, ..., b_field_a.

Is there a way to query tables without prepending the table names to the fields in the resulting table?

I want a final table with fields named `field_1, field_2, field_a (with the assumption that a and b don't have fieldnames that are identical).

Upvotes: 0

Views: 100

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172994

You can use BigQuery Standard SQL (see Enabling Standard SQL) where tables' aliases are not prepended so you can run your query as is and get expected result.

In BigQuery Legacy SQL you can use achieve this by explicitly listing fields to be in output

SELECT key_a, key_b, field_1, field_2, field_a
FROM dataset.table1 a
JOIN dataset.table2 b
  ON a.key_a = b.key_b

Upvotes: 2

Related Questions