SELECT
*,
p.name AS name,
p.image,
p.price,
(
SELECT ps.price
FROM product_special ps
WHERE p.id = ps.id
AND ps.date < NOW()
ORDER BY ps.priority ASC, LIMIT 1
) AS special_price,
(
SELECT ps.date
FROM product_special ps
WHERE p.id = ps.id
AND ps.date < NOW()
ORDER BY ps.priority ASC, LIMIT 1
) AS date
FROM product p LEFT JOIN product_special ps ON (p.id = ps.id)
As you can see I'm repeating the same subquery just to get another column out. I'm wondering is there a better way of doing this?
id is the primary key in both tables. I've no problem making product_special.priority unique if that can help.