SELECT c.id AS cat_id, c.title AS cat_title, s.title AS sub_title FROM category c LEFT JOIN subcategory s ON s.id IN (SELECT id FROM subcategory WHERE category_id = c.id LIMIT 2) ORDER BY c.title