I have the below query and it gives me the correct results for the most part. The only thing is that there can be multiple photo with the same userid and I want it to pull the most recently uploaded photo. Currently constituted it gives me a random photo. I have a timestamp field in tblimage, but I don’t know how to incorporate it into this query to pull the last photo uploaded.
SELECT tblimage.*, events.*
FROM (events LEFT JOIN tblfollowers
ON events.id_user = tblfollowers.username)
LEFT JOIN tblimage ON events.id_user = tblimage.userid
WHERE (((tblfollowers.follower_id)='$test')
AND (DATE_FORMAT(events.start_date,'%Y-%m-%d')='$today'))
OR (((tblfollowers.follower_id)='$test')
AND (DATE_FORMAT(events.end_date,'%Y-%m-%d')='$today'))
OR (((events.id_user) ='$test')
AND (DATE_FORMAT(events.start_date,'%Y-%m-%d')='$today'))
OR (((events.id_user) ='$test')
AND (DATE_FORMAT(events.end_date,'%Y-%m-%d')='$today'))
GROUP BY events.event_id
A few more details I thought I could share. tblimage has the following records for example:
userid=25 photo = 1.png timestamp = 12:00 jan 19
userid=25 photo = 2.png timestamp = 1:00 jan 18
I want it to give me just the photo on jan 19.
At the end include
GROUP BY tblimage.userid Order By tblimage.userid DESC
and you have already included the Goup by so you will get the latest picture of the user.