I have the following SQL query :
SELECT band.id bid, band.name, bandInfo.summary, bandImage.url bandImage,
user.username, user.online, userImage.url userImage
FROM bands AS band
INNER JOIN band_info AS bandInfo ON band.id = bandInfo.bid
LEFT JOIN band_images AS bandImage ON band.id = bandImage.bid
LEFT JOIN band_followers AS follower ON follower.bid = band.id
RIGHT JOIN users AS user ON user.id = follower.uid
INNER JOIN user_info AS userInfo ON userInfo.uid = user.id
LEFT JOIN user_images AS userImage ON user.id = userImage.uid
WHERE ((band.activated = 1) AND (user.activated = 1)) AND (bandInfo.language = 'fr')
ORDER BY band.name
'users' table contains all users (one row = one user)
'user_info' table contains all info about an user (one row = one user)
'user_images' table contains all image about users (one row = one user)
'bands' table contains all music bands (one row = one band)
'band_info' table contains all info about a band (multiple row for one band due to the language)
'band_images' table contains all image about bands (one row = one band)
'band_followers' table contains all relations between users and bands (one row = one relation so there are many row containing the same band id but not the same user id)
I would like to retrieve all bands with their info (INNER JOIN) EVEN IF the band id isn't in the band_followers table. I want to retrieve too all bands when the band id is in the band_followers table with an INNER JOIN on user id with the user's info (INNER JOIN) EVEN IF he doesn't have any image.
My problem is just the JOIN keyword.. I don't really know if I have to use LEFT or RIGHT JOIN
Thanks !
UPDATE ANSWER :
SELECT band.id bid, band.name, bandInfo.summary, bandImage.url bandImage, user.username, user.online, userImage.url userImage
FROM bands AS band
INNER JOIN band_info AS bandInfo ON band.id = bandInfo.bid
LEFT JOIN band_images AS bandImage ON band.id = bandImage.bid
LEFT JOIN band_followers AS follower ON band.id = follower.bid
LEFT JOIN users AS user ON user.id = follower.uid AND user.activated = 1
LEFT JOIN user_info AS userInfo ON userInfo.uid = user.id
LEFT JOIN user_images AS userImage ON user.id = userImage.uid
WHERE (band.activated = 1) AND (bandInfo.language = 'fr')
ORDER BY band.name
Thank you all