Trying to merge below two queries into one in the most "correct/efficient" way:
select id from TABLE1 where apple='green'
while{
select * from TABLE2 where id=[id from TABLE1 above]
while{
Eg query one will return a number of id's which in turn will return a number of rows in query two.
CodePudding user response:
You can try to use EXISTS
subquery
SELECT *
FROM TABLE2 t2
WHERE EXISTS(
SELECT 1
FROM TABLE1 t1
WHERE t1.apple='green' AND t1.id = t2.id
)