Frederic Bastiat
Frederic Bastiat

Reputation: 693

Referencing table name (dynamically) as a column in bigQuery

I think the answer uses Union but I'm having a hard time since I would like to query table names dynamically. At present I have:

SELECT
  id,
  created_on,
  operation,
  property_type,
  place_with_parent_names,
  floor,
  rooms,
  expenses,
  price_aprox_local_currency,
  description,
  title
FROM
  `properati-data-public.properties_mx.properties_sell_20*`
WHERE
  _TABLE_SUFFIX BETWEEN '1501'
  AND '1810'

I was trying to add tableName or something like that in the select section, but I couldn't get it right.

Upvotes: 1

Views: 2908

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173190

Add below to SELECT Statement

CONCAT('properties_sell_20', _TABLE_SUFFIX) table_name

Upvotes: 6

Related Questions