Quote:
Originally Posted by dtrobert
What I came up with works but isn't very efficient I feel
|
Don't "feel", test it and get a proof.
The execution plan will tell you if it's not efficient or if other statements are more efficient.
Code:
select * from phones p
where p.name not in (select cr.name from callrecord cr)
Note that this will return wrong results if cr.name can be NULL!
Quote:
|
I thought perhaps doing a left join and then distinct might help. I don't want the actual callrecords in the result, just the list of phones.
|
Use EXPLAIN ANALYZE on both statements and you'll see which one is better.
PostgreSQL's optmizier is pretty smart, and I wouldn't be surprised if both versions yield the same execution plan.
You should have an index on phones.name though.