Reputation: 392
I have this query:
SELECT id, header, title, price_obm, packs
FROM obm
WHERE id
IN (2, 12, 10, 2, 10)
ORDER BY FIELD(id, 2, 12, 10, 2, 10)
Now, I need to output multiple times the same rows (2, 10) which may vary (it can be any number).
How can I do this?
Output example:
id | header | title | price_obm | packs
2 | head2 | tit2 | price2 | p2
12 | head12 | tit12 | price12 | p12
10 | head10 | tit10 | price10 | p10
2 | head2 | tit2 | price2 | p2
10 | head10 | tit10 | price10 | p10
Upvotes: 1
Views: 1794
Reputation: 31637
Postprocess the result set using whatever programming language you are using to postprocess the data for presentation. Don't let MySQL do all the work.
A single query cannot produce the exact result that you desire, because the ORDER BY clause will always order the items with a common id
next to each other.
Upvotes: 4
Reputation: 1959
You can achieve this by using UNION
keyword.
You can found the example Here
Upvotes: 0