selecting rows where each value appears exactly once [message #427513] |
Fri, 23 October 2009 00:57 |
123soleil
Messages: 35 Registered: July 2006
|
Member |
|
|
Hello,
I have the following query:
select distinct c.id, a.key, h.addr
from asset a, asset_house ah, house h, client_house ch, client c
where [link all the tables together]
I would like to select only the rows where the client (c.id) appears exactly once.
my query so far:
select c.id, a.key, h.addr
from asset a, asset_house ah, house h, client_house ch, client c,
(select count(*), id from
(select distinct c.id, a.key, h.addr
from asset a, asset_house ah, house h, client_house ch, client c
where [link all the tables together])
group by id
having count(*) = 1
) sq
where sq.id = c.id
and [link all the tables together]
I'm basically rewriting the main query in the subquery... is there a better way of doing this?
|
|
|
|
|
|
|