A difficult query
From: Conny Roloff <connyroloff_at_gmx.de>
Date: 7 Sep 2002 16:43:10 -0700
Message-ID: <f81368f0.0209071543.734e1f2f_at_posting.google.com>
Date: 7 Sep 2002 16:43:10 -0700
Message-ID: <f81368f0.0209071543.734e1f2f_at_posting.google.com>
I can't find a fine solution for my problem:
2, 3, 4,X <-- not wanted, because it's marked 5, <-- not wanted, because it's not in table A
Needed result:
1
2
3
I ended up in this:
select id from A where not exists
(select * from B where A.id = B.id and mark='X')
union
select id from B where exists
(select * from A where A.id = B.id)
But this seems to me a bit complicated. In reality both main selects are very complex, so that I get a huge resulting SQL-statement which is probably not quite performant (In fact I generate it by java).
Does somebody know a better solution?
Thx in advance for each little hint.
Conny Received on Sun Sep 08 2002 - 01:43:10 CEST