Code:
SELECT tn, carId, photoId
FROM Car INNER JOIN CarP ON Car.carId = CarP.carFk
LEFT JOIN (
SELECT MIN(photoId) AS photoId, carFk, tn
FROM Photos
GROUP BY carFk) AS Photos
ON Photos.carFk = Car.carId
I am getting a different result than what I think I should be getting.
When I output both "tn" and "photoId", the photoId results correctly with the lowest value for that column (for carFk), however the "tn" does not result from the same row as the photoId, it results from a different row.
It appears that the "tn" results in the lowest value and it not linked to the photoId row.
I thought SELELT MIN() returned the row for the lowest value for the column within the ().