TigSh
TigSh

Reputation: 645

Using update with Left Join BigQuery

I am trying to write an Update query with LEFT JOIN in BigQuery but I am not sure how to write it.

  update Table1
  set ColumnTest =  ifnull(b.value, 'no run')
  From left join  (select distinct ID,value FROM Table2 where value = 10) B  --
  where Table1.ID= Table2.ID

I have 2 tables Table1 and Table2

I want to update Table1.ColumnTest with Table2.Value where Table1.ID= Table2.ID and if Table1 <> Table2 then update Table1.ColumnTest with 'no run'

Thanks!!

New Try

  UPDATE Table1
  SET LP = IFNULL(t2.value, 'no run')
  FROM (     select distinct hits.eventInfo.eventCategory as ID, value
       FROM Table2
       CROSS JOIN UNNEST (hits) AS hits
       left join  TAble1 using (hits.eventInfo.eventCategory)
       WHERE) t2
 WHERE t1.ID = t2.ID

Error: Syntax error: Expected ")" or "," but got "."

Upvotes: 0

Views: 2934

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173046

I want to update Table1.ColumnTest with Table2.Value where Table1.ID= Table2.ID and if Table1 <> Table2 then update Table1.ColumnTest with 'no run'

Below is for BigQuery Standard SQL

UPDATE `table1` t1
SET ColumnTest = IFNULL(value, 'no run')
FROM (
  SELECT id, value
  FROM `table1`
  LEFT JOIN `table2`
  USING(id) 
) t2
WHERE t1.id = t2.id

Upvotes: 1

Related Questions