Hi Ralf,

> I've got two tables A, B
>
> Now I want the entries from B with no corresponding entry in A
>
> I did the following:
>
> Select id.field from B
>
> Where (select count(id.field) from A) = 0
>
> Unfortunately it didn't work, the query should have returned 1 entry.
>
> Where is my mistake?

Firstly, it's inefficient to use count() here since you only care  
whether it exists or doesn't, so counting through the whole table is  
unnecessary. Using "in" would be equally inefficient.

Try this:

select ID from B
where not exists (select 1 from A where A.ID = B.ID)
;

Or you could use this:

select ID from B
except
select ID from A
;

Tom
BareFeet

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to