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 8350465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:19:55+00:00 2026-06-09T08:19:55+00:00

I have the following query but it’s returning multiple entries from the profile_photos table.

  • 0

I have the following query but it’s returning multiple entries from the profile_photos table. Is it possible to return just one random entry from the profile photos table? If not random is it possible to limit the number of results to 1?

Here is my current query:

$sql = "SELECT * FROM login_users " .
       "LEFT JOIN profile_photos ON profile_photos.user_id = login_users.user_id " .
       "LEFT JOIN profiles ON profiles.user_id = login_users.user_id " .
       "WHERE login_users.restricted <> 1 " .
       "ORDER BY login_users.birthdate DESC " .
       "LIMIT 0, 20";
  • 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-09T08:19:56+00:00Added an answer on June 9, 2026 at 8:19 am

    Here is one method. Look up a random photo and then join in the additional information:

    SELECT *
    FROM (select lu.*,
                 (select photo_id
                  from profile_photos
                  where lu.user_id = profile_photos.user_id
                  order by RAND()
                  limit 1
                 ) as photo_id
          from login_users lu
         ) lu LEFT JOIN
         profile_photos pp
         ON pp.photo_id = lu.photo_id LEFT JOIN
         profiles p
         ON p.user_id = lu.user_id 
    WHERE lu.restricted <> 1
    ORDER BY lu.birthdate DESC
    LIMIT 0, 20
    

    This assumes that photo_id is the primary key on profile_photos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: SELECT timestamp, COUNT(*) FROM table GROUP BY timestamp But
I have the following query. It works just fine but I need to pull
I have the following xpath query which seems to be working but I just
I need some help with query from multiple tables. My database: I have following
I have the following query: SELECT COLUMN1, COLUMN2, COUNT(*) FROM TABLE WHERE COLUMN3 IS
I have following query, but it doesn't return any results for where clauses, even
I have the following query that executes perfectly in MySQL, but it is giving
I have the following query which is working fine, but I also want to
I have the following query which gives me the right results. But it's super
I have the following tables. I want to run a query but I think

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.