I have the following query that selects a friend request script that shows the profile pic, the hometown, the userid, and the full name of a user that has requested to be friends with a certain user.
SELECT
a.hometown,
a.first_name,
a.uid,
a.last_name,
b.friend_one,
b.friend_two,
b.friend_request_id,
p.thumbnail
FROM
users a,
friend_requester b,
profile_pics p
WHERE
a.uid = b.friend_one
AND b.friend_two = $uid
AND p.uid_fk = $uid
ORDER BY b.created DESC LIMIT 5
My problem is that instead of returning 1 user for each query found in the friend_requester table, I return 3 instances for example of the same user with different profile pictures. So if a user has uploaded 3 profile pictures which will be stored as
id=1, profile_pic=profile_pic1.jpg...
id=1 profile_pic=profile_pic2.jpg...
id=1 profile_pic=profile_pic3.jpg...
I get 3 different boxes of the same user asking to be friends with the logged-in user.
As Hituptony mentioned, I would want to select the latest inserted picture which would be from the ‘profile_pics’ table in the column ‘created’.
GROUP BY Uid_FK, get the max created and INNER join back to the picture table (done in my subquery called “MaxPic”)