SELECT Category.id AS CategoryID, Category.name AS CategoryName, IF( Category.id IN ( SELECT CategoryProduct.category_id FROM category_product as CategoryProduct WHERE CategoryProduct.product_id = 5 ), 'SELECTED', NULL ) AS Selected FROM Categories AS Category