I want to make a query where I select all the IDs of table A, which ids will connect to existing values of end_date in table B. I need to get the IDs of table A which will connect only to finished IDs(i.e. with existing end_date) on B table. Relation of table a and b is one to many . A can correlate to many Bs . B will always correlate to one A table.
I have made something like this:
select id
from A
where not exists
(select 1
from B
where end_date is null
and A.id=B.id)
Is this correct? Or is there a faster query for the same thing?
EDIT:
end_date is in table B
example : In the data set:
A.id=1
B.id=1
B.bid=333
B.end_date=null
A.id=1
B.id=1
B.bid=334
B.end_date=05/05/2014
A.id=2
B.id=2
B.bid=335
B.end_date=null
A.id=2
B.id=2
B.bid=336
B.end_date=null
A.id=3
B.id=3
B.bid=337
B.end_date=04/04/2014
A.id=3
B.id=3
B.bid=338
B.end_date=04/04/2014`
My query should result only id=3.