SELECT * FROM `cat` AS A LEFT JOIN `database` AS B ON A.id = B.cat_id GROUP BY A.name LIMIT 0 , 30