Gisela Kottmeier
Gisela Kottmeier

Reputation: 43

How to chain where and where not in in sql?

I have these two queries working:

var queryOne = client.query("SELECT * FROM tableone WHERE (tableone.id) NOT 
  IN ( SELECT tabletwo.id FROM tabletwo)");
var queryTwo = client.query("SELECT * FROM tableone WHERE time = 1")

I am attempting to combine them into one query:

var finalQuery = client.query("SELECT * FROM tableone WHERE time = 1 AND
  WHERE (tableone.id) NOT IN ( SELECT tabletwo.id FROM tabletwo)");

However, I am running into this error: syntax error at or near "WHERE"

How can I correctly, combine the two queries?

Upvotes: 2

Views: 1161

Answers (1)

Nir Levy
Nir Levy

Reputation: 12953

drop the second WHERE, it's not needed:

var finalQuery = client.query("SELECT * FROM tableone WHERE time = 1 AND 
(tableone.id) NOT IN ( SELECT tabletwo.id FROM tabletwo)");

Upvotes: 4

Related Questions