Is it possible to create a MySQL query like this:
SELECT id, name FROM products WHERE id IN ( 36, 36, 34, 2 )
So that because the id '36' is included twice, it produces two rows of that product in the result?
i.e. the result set might be:
id name
36 Cool Product
36 Cool Product
34 Lame Product
2 Mediocre Product
Instead of:
id name
36 Cool Product
34 Lame Product
2 Mediocre Product
Or possibly to consider it as a 'quantity', like:
id name qty
36 Cool Product 2
34 Lame Product 1
2 Mediocre Product 1
Thanks for the help!
解决方案SELECT id, name, COUNT(name) AS qty
FROM products p
WHERE p.id IN ( 36, 34, 2 )
GROUP BY id, name
That said, that is assuming your products table has duplicate records which seems wrong.