Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:19:29+00:00 2026-06-05T10:19:29+00:00

I have the following query that selects a friend request script that shows the

  • 0

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’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:19:31+00:00Added an answer on June 5, 2026 at 10:19 am

    GROUP BY Uid_FK, get the max created and INNER join back to the picture table (done in my subquery called “MaxPic”)

    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
            INNER JOIN friend_requester b 
                ON b.friend_one = a.uid
            INNER JOIN profile_pics p 
                ON p.uid_fk = b.frind_two
            INNER JOIN
            (   SELECT  uid_FK, MAX(Created) AS Created
                FROM    Profile_Pics
                GROUP BY uid_FK
            ) MaxPic
                ON MaxPic.UID_FK = p.UID_FK
                AND MaxPic.Created = p.Created
    WHERE   p.uid_fk = $uid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following SQL query that selects some results from my table: select avg(c3),
I have the following LINQ query that selects all the pages that have a
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have the following query that retrieve the number of users per country; SELECT
Dear all, I have a select query that currently produces the following results: DoctorName
I have two tables that I am joining with the following query... select *
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following query that needs to be converted from Oracel PL/SQL to
I have the following query that I need to convert to rails like syntax.
I have the following query that runs in my Oracle database and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.