MySQL Forums
Forum List  »  Newbie

Re: SQL query to return all matching condition
Posted by: Roland Bouman
Date: July 06, 2005 05:20AM

Ok, I think i misread your original question. Sorry about that.

This should work:

SELECT name, category
FROM contact c
WHERE exists (
select null
from contact cat1
where cat1.name = c.name
and cat1.category = 'cat1'
)
and exists (
select null
from contact cat2
where cat2.name = c.name
and cat2.category = 'cat2'
)

That is, all rows for which there is one row in category 1
and one row in category 2

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.