MySQL Forums
Forum List  »  Newbie

Re: Column condition two times
Posted by: Phillip Ward
Date: June 16, 2016 06:23AM

Quote

SELECT * FROM `node_index` n LEFT JOIN `category` c on n.oid = c.oid WHERE c.cid = 1 AND c.cid = 2 GROUP by n.oid;
The SQL is wrong but is want I want.

The HAVING clause is what you're looking for:

select    n.oid 
from      node_index n 
left join category c 
     on   n.cid = c.cid 
where     c.cid in ( 1, 2 ) 
group by  n.oid
having    count( c.cid ) = 2 
order by  n.oid ;

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Column condition two times
June 16, 2016 06:23AM


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.