I'm having trouble getting the correct results in my query. I'm using Mysql and here is what I have so far:
SELECT cpn, status, title, value_category, rating_category, parts.id
FROM `vendors`
INNER JOIN `vendor_parts` ON (`vendors`.`id` = `vendor_parts`.`vendor_id`)
INNER JOIN `parts` ON (`parts`.`id` = `vendor_parts`.`part_id`)
WHERE (concat(IFNULL(vendors.name,''),IFNULL(vendors.abbreviated_name,''))
LIKE '%vendor1%'
OR
CONCAT(IFNULL(vendors.name,''),IFNULL(vendors.abbreviated_name,''))
LIKE '%vendor2%')
GROUP BY cpn
HAVING COUNT(cpn)=2
ORDER BY cpn
The problem is that for some rows in the parts table, there are multiple rows of the same vendor name in the vendors table. Thus in the result set I would get parts that have two vendor1's instead of a vendor1 and a vendor2. I'm trying to get parts that have at least one of both vendor1 and vendor2.
Any ideas?