$sql = "SELECT products.*, cat1.*, cat2.cat_name as parent_name, cat2.cat_url as parent_url
FROM `categories` AS cat1
LEFT JOIN `categories` AS cat2
ON cat2.id = cat1.parent
INNER JOIN products
ON cat1.id = `products`.cat_id
WHERE cat1.`cat_url` = :category_url AND `products`.url = :product_url";