I'm struggling extracting all the information I need from a MySQL query. I am almost there but need help just getting seperate values.
My aim is to gather any company in the table which has all the products provided by an array. The information is provided by the end user through the use of AJAX.
The query also needs to be slightly fluid as the array in which the product_ids are provided in, can be infinite.
My query is as follows:
SELECT `company_id`, `product_id`, COUNT(*) as c
FROM `products`
WHERE `product_id` IN (2495, 2403)
GROUP BY `company_id`
HAVING c = 2
The output provided by this query is (A):
| company_id | product_id | c |
-------------------------------
| 1234 | 2495 | 2 |
But what I am after is (B):
| company_id | product_id | c |
-------------------------------
| 1234 | 2495 | 2 |
| 1234 | 2403 | 2 |
or even better (C)
| company_id | product_id A | product_id B | c |
------------------------------------------------
| 1234 | 2495 | 2403 | 2 |
Any help on this would be appreciated, so thanks in advance!