Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Syntax NOT IN for Google BigQuery

The Google SQL syntax guide found here https://developers.google.com/bigquery/docs/query-reference does not seem to address use of the NOT IN terminology.

I get the error

Query Failed
Error: Encountered "" at line 0, column 0. Was expecting one of:  

(and then Google lists nothing after the words 'one of')

when my query is

SELECT ageinmonths,amountborrowed,borrowerrate,creationdate,creditgrade,
       debttoincomeratio,groupkey,key,lenderrate,listingkey,modifieddata,
       originationdate,prosperrating,status,term
FROM prosperloans1.loans2 as big,
     prosperloans1.dupelistingkeysinloans2 as small
WHERE big.listingkey NOT IN small.listingkey

the table 'small' has 14 rows. The table big has 57K rows.

Any ideas? Not sure if Google SQL supports NOT IN.

Thanks Shawn

like image 548
user1558422 Avatar asked Jul 30 '12 20:07

user1558422


People also ask

What SQL syntax does BigQuery use?

BigQuery supports the Google Standard SQL dialect, but a legacy SQL dialect is also available. If you are new to BigQuery, you should use Google Standard SQL as it supports the broadest range of functionality. For example, features such as DDL and DML statements are only supported using Google Standard SQL.

How do you write not equal to in BigQuery?

NOT EQUAL TO (!=) and EXISTS... EQUAL TO Giving Different Results.

Where is not in SQL?

Description. The SQL NOT condition (sometimes called the NOT Operator) is used to negate a condition in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.

How does Google BigQuery differ from a traditional SQL?

Google BigQuery is a cloud-based Architecture and provides exceptional performance as it can auto-scale up and down based on the data load and performs data analysis efficiently. On the other hand, SQL Server is based on client-server architecture and has fixed performance throughout unless the user scales it manually.


1 Answers

Semijoins and antijoins use the following syntax: SELECT field FROM table WHERE field [NOT] IN (SELECT other_field FROM other_table WHERE foo = 'bar')

So your updated query with the subselect is the correct version.

like image 103
Jordan Tigani Avatar answered Oct 19 '22 20:10

Jordan Tigani