Is there alternative way to write this query?
Posted
by Kugel
on Stack Overflow
See other posts from Stack Overflow
or by Kugel
Published on 2010-06-06T23:03:22Z
Indexed on
2010/06/06
23:12 UTC
Read the original article
Hit count: 289
I have tables A, B, C, where A represents items which can have zero or more sub-items stored in C. B table only has 2 foreign keys to connect A and C.
I have this sql query:
select * from A
where not exists (select * from B natural join C where B.id = A.id and C.value > 10);
Which says: "Give me every item from table A where all sub-items have value less than 10.
Is there a way to optimize this? And is there a way to write this not using exists
operator?
© Stack Overflow or respective owner