SELECT f.id FROM firms AS f
WHERE f.id NOT IN (SELECT c1.firm_id FROM calls AS c1) OR f.id IS NULL
union
SELECT f2.id FROM firms AS f2
WHERE f2.id IN (SELECT c2.firm_id FROM calls AS c2)
order by (c1.last is null, c2.last is not null)

I have two tables firms and calls.
I'd like to list all the firms for which no calls records exist
then
I'd like to list all firms for which calls records DO exist
in order of earliest last call first i.e. the one I'd called furthest back
first
if that makes sense.
Igore helped me last time with an order by (), coalesce() structure
but I can't see how to map this to my current problem
Any advice very much appreciated.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to