Reputation: 23
I have galleries and photos in all galleries.
Is possible "in only one query" to list the photos of last the gallery? The last gallery is the most recently date
For example:
table "gallery" with field "data" and table "fotos" with fields "file" and "gallery_fk"
Thanks
Upvotes: 1
Views: 97
Reputation: 12628
Try:
SELECT * FROM fotos WHERE gallery_fk = (SELECT MAX(id) FROM gallery);
Assuming your gallery-table has an id-field (which would refer to "gallery_fk" in table "fotos") to retrieve whatever you mean with "last gallery", here the highest id would be the "last gallery" (otherwise you could add a date-field and select the "latest" from that).
Upvotes: 1
Reputation: 166396
By using a sub select and MySql LIMIT (Sql Server TOP), you can try something like
SELECT *
FROM (
SELECT *
FROM Galeries
ORDER BY
DATE DESC
LIMIT 1
) LatestGalery INNER JOIN
Fotos f ON LatestGalery.GaleryID = f.GaleryID
Upvotes: 1