LIBRARY

 
    SELECT 	
	gal.mg_id,
	gal.title,  
	ph.filename 
    FROM media_gallery gal
    JOIN media_photo ph ON gal.mg_id=ph.category 
    WHERE gal.category_id=2 AND gal.status=1
    GROUP BY gal.mg_id
    ORDER BY gal.order_id 
 LIMIT 18, 6