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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:08:54+00:00 2026-06-03T15:08:54+00:00

I know there are already some solutions to this question but they don’t seem

  • 0

I know there are already some solutions to this question but they don’t seem to be working for me.

I want to select the last record from each day, per user, on my database. I have a database that stores a user’s location by country and date down to the second.

The select query I’m trying to run is:

SELECT MAX(date), id, country FROM dk_location_records WHERE userid = '10'
AND (date > '2012-04-06 00:00:00' AND date < '2012-05-08 23:59:59')
AND active = '1' GROUP BY DATE(date) ORDER BY date ASC

However, what this actually does is show me the last date from each day, but not the correctly corresponding id and country. It actually gets the first id and country, alongside the last date.

What am I doing wrong?

Help greatly appreciated!

Thanks,

Jack

  • 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-03T15:08:57+00:00Added an answer on June 3, 2026 at 3:08 pm

    Try this query to show last record from each day, per user, –

    SELECT t1.* FROM dk_location_records t1
      JOIN (SELECT DATE(date) date_date, userid, MAX(date) max_date
            FROM dk_location_records
            GROUP BY date_date, userid
            ) t2
        ON t1.date = t2.max_date AND t1.userid = t2.userid;
    

    …add your WHERE conditions if you need.

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

Sidebar

Related Questions

There's already a question on this here. But i want to know if its
I know there's already a lot of questions on this topic but I might
This is presumable a simple C++ question, but I'm relearning C++ and don't know
I know there are already objects supporting Office 2007 files, but is there any
I know there are already many questions like mine but I found no answer
I know there are a few questions on stack already regarding this, and I
First of, I know there are similar questions already on stackoverflow ( this ,
I already know that most implementations use a single thread, but is there anything
My apologies if similar questions already exist (I know they do), but I didn't
I would like to know if maybe there are some good solutions to handling

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.