I have the following sql statement:
WITH subquery AS ( select distinct id from a_table where some_field in (1,2,) ) select id from another_table where id in subquery; Edit
JOIN is not an option (this is just a reduced example of a bigger query)
But that obviously does not work. The id field exists in both tables (with a different name, but values are the same: numeric ids). Basically what I want to do is filter by the result of the subquery, like a kind of intersection.
Any idea how to write that query in a correct way?
... IN (SELECT id FROM subquery) ...But I would recommend to rewrite it as aJOIN.another_table? I'm aware of the JOIN option, but that's not possible (that just a reduced example of another query).INorEXISTS. You only got the syntax wrong. sticky bit's IN clause should work just fine for you.