(SELECT id,category_id FROM contents where category_id=1 ORDER BY published DESC limit 4)
UNION
(SELECT id,category_id FROM contents where category_id=2 ORDER BY published DESC limit 4)
UNION
(SELECT id,category_id FROM contents where category_id=3 ORDER BY published DESC limit 4)
UNION
(SELECT id,category_id FROM contents where category_id=4 ORDER BY published DESC limit 4)
order by category_id