Two tables P, W are connected by Group foreign key. The bellow inner SQL returns only the table P 'names' which has only one matching 'type' in W table. The outer SQL displays name and type column values.
Basically i need to retrieve only the names(p) who has only one type (W).
The bellow statement is correct, however, i wonder if i can do it without inner SQL or any other better solution.
select p.name, w.type
from p, w
where p.name in
(
select p.name
from P , w
where p.group = w.group
group by p.name
having count(w.type) = 1
)
AND
p.group= w.group