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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:41:19+00:00 2026-05-27T15:41:19+00:00

I am attempting to return the data from the rows with the most recent

  • 0

I am attempting to return the data from the rows with the most recent date of each distinct candidate_id. It is correctly returning the most recent date (the created_unix column), but not the rest of the data from the corresponding row.

SELECT candidate_id, message, max(created_unix), jobpost_id, staffuserid 
    FROM messages 
       WHERE employer_id='$employerid' AND last='company' 
          GROUP BY candidate_id
  • 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-05-27T15:41:19+00:00Added an answer on May 27, 2026 at 3:41 pm

    You must group by everything not using an aggregate function:

    SELECT candidate_id, message, max(created_unix), jobpost_id, staffuserid 
        FROM messages 
           WHERE employer_id='$employerid' AND last='company' 
              GROUP BY candidate_id, message, jobpost_id, staffuserid 
    

    If your message is different per row and you want to group by candidate_id, then you must not be using message. In that case, simply remove it from your select list and you won’t need it in your group by list. The same goes for any other field you aren’t using.

    Remember, when using aggregate functions, you must contain each field in either an aggregate function or the group by. Otherwise, SQL won’t know from which row to pull the data for the row returned.

    Update:

    After seeing what you’re looking for, this will do the trick:

    SELECT candidate_id, message, max(created_unix), jobpost_id, staffuserid 
        FROM messages 
           WHERE employer_id='$employerid' AND last='company' AND
           created_unix = (
               SELECT max(subm.created_unix)
               FROM messages subm
               WHERE subm.candidate_id = messages.candidate_id
           )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to return a collection of departments from a .NET assembly to
I am attempting to return a rowcount from a subquery as part of a
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to insert data into a local SQLITE database file from a
I am attempting to collect data from a user in the form of an
I am attempting to create a data set from an original dataframe (in either
I am attempting to take the Name and ID fields from each object, but
I'm attempting to create an app to pull the sqlite data from a preexisting
I'm attempting to implement the technique for data validation from Josh Smith's example here:
I am attempting to reload the data from my tableView. When calling it from

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.