A bit new to mysql and just want to see if im doing things correctly!
Im basically getting a row on a user and also counting how many albums the user has.
tables: users, albums
norm table: albums_users
SELECT u.id,u.name,
(
SELECT COUNT(a.id) FROM albums a
LEFT JOIN albums_users au ON au.user_id = u.id
) AS total
FROM users u WHERE u.id IN(398,3247)
I then (i need users showing even if 0 albums or i would do a HAVING total > 0)
do an if statement in PHP to check if TOTAL > 0 if it is then retrieve some albums
SELECT a.id,a.image,a.name FROM albums a
LEFT JOIN albums_users au ON au.album_id = a.id
WHERE au.user_id = 398 ORDER BY a.date_added LIMIT 5
i norm the tables b/c it is a 1 to many users
just need some criticism to up my game...just wanna see if im doing things correctly.
Thanks for your time