I need to get the smallest value of a column to use as a condition in where
, but I do not know how to do that. The column I need is ordering
, as below:
SELECT p.pro_name, p.id, f.image as foto
FROM #__osrs_properties p
LEFT JOIN (
SELECT image, pro_id
FROM #__osrs_photos
WHERE ordering = "menor ordering"
) f ON f.pro_id = p.id
ORDER BY pro_name DESC
LIMIT 21
The tables look like this:
osrs_properties
id|pro_name
1 | joao
2 | nome
3 | maria
osrs_photos
id|pro_id| image | ordering
1 | 1 | imagem1.jpg | 2
2 | 1 | imagem2.jpg | 1
3 | 2 | imagem3.jpg | 1