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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:27:37+00:00 2026-06-18T04:27:37+00:00

I have a hypothetical table users with the columns user_id (auto incremented) name foo

  • 0

I have a hypothetical table “users” with the columns

  • user_id (auto incremented)
  • name
  • foo
  • bar
  • last_updated

This table is updated multiple times per day. How can I query to get the last update, per user, per day, going back X days?

Example Data

1 John a b "2013-01-31 02:01:12"
2 Rich c d "2013-01-31 22:41:12"
3 John e f "2013-01-31 22:01:15"
4 Rich g h "2013-02-01 16:01:12"
5 John i j "2013-02-01 22:21:12"
6 Rich k m "2013-02-01 22:21:12"

Desired Return Set:

2 Rich c d 2013-01-31
3 John e f 2013-01-31
5 John i j 2013-02-01
6 Rich k m 2013-02-01

I am able to get the last updated per user overall with the following query, it’s applying it to each day that I am struggling with.

SELECT u1.*
FROM users u1 
    LEFT JOIN users u2
    ON (u1.name = u2.name AND u1.user_id < u2.user_id)
WHERE u2.user_id IS NULL
  • 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-18T04:27:38+00:00Added an answer on June 18, 2026 at 4:27 am

    First of all the table name users is very confusing, since these aren’t the users but the logins.

    Beyond that you’re on the right way. You just need to add a comparison on the date in the join.

    SELECT u1.*
    FROM users u1
        LEFT JOIN users u2
        ON (u1.name = u2.name AND date_format(u1.last_updated, '%Y-%m-%d') = date_format(u2.last_updated, '%Y-%m-%d') AND u1.user_id < u2.user_id)
    WHERE u2.user_id IS NULL
    

    See it work in this SQL fiddle.

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

Sidebar

Related Questions

I have two tables named foo and bar , hypothetically speaking. foo has columns
I have this hypothetical table: +----+---------+-------+ | id | type_id | value | +----+---------+-------+
This question requires some hypothetical background. Let's consider an employee table that has columns
Pretend I have this table, hypothetically representing users (the voters) rating various objects (e.g.
I have a hypothetical tree view that contains this data: RootNode Leaf vein SecondRoot
Suppose I have this hypothetical, odd and unintuitive situation #include <iostream> struct A {
(This is a hypothetical question for discussion, I have no actual problem). Say that
I want to have a column on a table that is automatically updated when
There is a hypothetical table called Table1, with the columns: id condition 1 condition
Ok, so lets say I have a table comprising three columns. The first column

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.