Y
Hacker News
new
|
ask
|
show
|
jobs
by
anshul
1403 days ago
You might want to test using the first query as a sub-query or cte in the second one. That would likely give you the same / better perf. It would avoid the join and save a round trip.
1 comments
hobs
1402 days ago
If you dont need the output of the first query you'll almost always have the best performance in sql using exists syntax eg
select * from query1 as q where exists ( select * from query2 as q2 where q.col = q2.col )
link
nfcampos
1402 days ago
Yes although in this specific case you’d lose the order of the results with exists
link
select * from query1 as q where exists ( select * from query2 as q2 where q.col = q2.col )