Please Help Fix This Code

This select statement displays all the members that have view another members profile. The only problem is if the member that has viewed the other member has more than one photo on his/her profile all the pictures are showing. I’m only trying to show one picture for each member. Can you please help? I don’t know where to put the DISTINCT part

SELECT rate_profile_views., rate_members., rate_pictures.* FROM rate_profile_views LEFT JOIN rate_members ON v_by=m_id LEFT JOIN rate_pictures ON i_user=m_id WHERE v_for=m_id AND i_status>0 AND m_confirmed !=0 AND m_type !=<%m_type%> ORDER BY v_time DESC LIMIT 52

If there is more than 1 photo then a DISTINCT will not help. DISTINCT will only display UNIQUE records (or in this case photos).

I think what you need to do is separate you query and take the picture part out. Do the main query and then do another query to get the picture separately.

how is that done exactly…can i have some examples? i’m stuck


I could be wrong, but I think you need to add a group by. It’s hard to really give advice for queries without table structures.


‘Group by’ solve the problem. Thanks all

Sponsor our Newsletter | Privacy Policy | Terms of Service