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

  • Home
  • SEARCH
  • 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 9232329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:17:17+00:00 2026-06-18T06:17:17+00:00

I am trying to pull the photo from tblimage that corresponds to the maxid

  • 0

I am trying to pull the photo from tblimage that corresponds to the maxid in the tblimage for each user. Currently, I am getting all the messages from the message table and a random photo for the user that posted the message, I would like the photo to be the latest uploaded photo. the way its written now it just pulls a random photo from the table. any suggestions?

table structures are as such:

messages: msgid, message, user_id, event_id
tblimage: id, photo, userid

SELECT messages.*, tblimage.photo, max(tblimage.id) 
        FROM messages LEFT JOIN tblimage ON messages.user_id = tblimage.userid 
        GROUP BY messages.msg_id, messages.user_id 
        ORDER BY messages.msg_id DESC, tblimage.id desc
  • 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-18T06:17:19+00:00Added an answer on June 18, 2026 at 6:17 am

    Try

    SELECT messages.*, T2.photo
    FROM messages
    LEFT JOIN (SELECT userid, MAX(id) AS maxid
               FROM tblimages
               GROUP BY userid) AS T1
    ON messages.user_id = T1.userid
    LEFT JOIN tblimages AS T2
    ON T2.id = T1.maxid
    ORDER BY messages.msg_id DESC
    

    which finds max(id) for each user in tblimages, then uses that to join each user to the latest photo for that user.

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

Sidebar

Related Questions

So, I'm trying to pull all photos of a specific user's account via the
Trying to pull user images via the Facebook Social Graph. Finding it odd that
I was getting a confusing error message after trying git pull about no matching
Trying to pull info from one JSON datafeed and use that to make another
Just trying to pull off some SMART info from connected Hard Drives on any
I'm trying to pull data from the YouTube API into a local MySQL table.
I am trying to pull a specific set of records from a table called
I am trying to pull an LDAP jpegPhoto attribute from an openLDAP server using
I'm trying to pull a project from git, in particular, this one: https://github.com/pocmo/Yaaic .
Trying to pull data from parse.com and use underscore.js I tried using this to

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.