bins
----
id min max
1 1 20
2 21 40
3 41 60
pictures
--------
id
3
11
59
Basically, I want to select the highest picture Id and then select from the bin table the bin id it matches. For example, for a pictures.id = 59 (highest), I want bins.id = 3. Can anyone help me with such a query? Something like
SELECT bins.id AS id
FROM bins
JOIN pictures.id
ON bins.min < MAX(pictures.id)
AND bins.max > MAX(pictures.id)
doesn't appear to work. Thanks!