问题
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 "."
回答1:
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
来源:https://stackoverflow.com/questions/63889590/using-update-with-left-join-bigquery