Joining 3 three tables
10,619
Using an INNER JOIN will prevent returning albums that don't have images. The ORDER BY ... DESC will sort the results in descending order but I'm not sure how to only return the last record. It would take some sort of combination of ORDER BY, GROUP BY and TOP, perhaps.
SELECT
album_table.album_id,
album_table.album_name,
images_table.filename
FROM album_table
INNER JOIN images_table ON images_table.album_id = album_table.album_id
WHERE album_table.user_id = uid
ORDER BY images_table.date DESC
Comments
-
MacMac over 1 year
I have this diagram which should explain my situation I need some help on joining 3 tables which I have no idea how to do this kind of thing:
So I can go through a while loop of retrieving the records by doing this:
<img src="<?php echo $row['filename']; ?>" alt="" /> Album: <?php echo $row['album_name']; ?> AlbumID: <?php echo $row['album_id']; ?>