Question

How do I convert following sql to bigquery

SELECT table1.field1, table2.field2, table2.field3, table2.field4, table2.field5, table2.field6, table2.field7 
FROM table1
JOIN EACH table2 on table1.cookie=table2.cookie 
GROUP BY table2.field3,table1.field1,table2.field2,table2.field4,table2.field5,table2.field6,table2.field7
WHERE table2.field3=1176;

I am getting following error " Encountered " "WHERE" "WHERE "" at line 2, column 1 "

Was it helpful?

Solution

Your WHERE is in the wrong place. WHERE should be before GROUP BY and after the last JOIN or after FROM if there are no JOINS.

Try this:

SELECT table1.field1, table2.field2, table2.field3, table2.field4, table2.field5, table2.field6, table2.field7 
FROM table1 
JOIN EACH table2 on table1.cookie=table2.cookie 
WHERE table2.field3=1176;
GROUP BY table2.field3,table1.field1,table2.field2,table2.field4,table2.field5,table2.field6,table2.field7 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top