I have a table with prodID , attrID Each prodID have 1-5 atrrID's I want to list the prodIDs which don't have a specific atrrID, eg "c"
+-----------+---------+
| prodID | attrID |
+-----------+---------+
| 1 | a |
| 1 | b |
| 1 | c |
| 2 | a |
| 2 | b |
| 2 | d |
| 3 | b |
| 3 | c |
| 3 | d |
| 4 | a |
| 4 | b |
| 4 | d |
| 4 | e |
| 5 | a |
| 5 | b |
| 6 | a |
| 6 | d |
+-----------+---------+
The result should be
+-----------+
| prodID |
+-----------+
| 2 |
| 4 |
| 5 |
| 6 |
+-----------+
Table name is rp_prod_attr_list
You can use
group by
andhaving
:In MySQL, a condition evaluated in numeric context returns
1
if fullfilled, else0
. Somax(attr_id = 'c') = 0
phrases as: there is no row in the group that satisfies the condition.