Monday, March 19, 2012

Getting records that only exist once.

Heres one that I'm too dumb to fathom out - have spent hours on it so any help would be greatly received :-)

I have a database that lists company names. What I need to do is only select those companies that appear in the table once. - bear in mind a distinct wont work for this.

So far I have tried this:

select total,num_dels,company from nominput where (select count(company) from nominput) = 1

But this doesn't return a thing - is this the right way to do it ?

Many Thanks
Phil
:(select total
, num_dels
, company
from nominput
where company in
( select company
from nominput
group by company
having count(*) = 1 )|||Many thanks - works great :-)

I guess I need to do some more reading up on group by, I dont understand why it works but it does so thanks very much, greatly appreciated.

Phil

No comments:

Post a Comment