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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:50:57+00:00 2026-05-17T00:50:57+00:00

I have a table setup like this (simplified for example): user_id item_id click_dt Each

  • 0

I have a table setup like this (simplified for example):

user_id
item_id
click_dt

Each item_id has many user_id’s. Basically it’s storing the clicks on items, associated to a user_id.

I want to query through this and list only the latest user_id for each item_id, based on click_dt.

So if there are 5 clicks for item_id 55, the last click or click_dt DESC would be the record to show….

Make sense? Any help would be awesome… thanks!

  • 1 1 Answer
  • 1 View
  • 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-17T00:50:57+00:00Added an answer on May 17, 2026 at 12:50 am

    Use:

    SELECT x.*
      FROM YOUR_TABLE x
      JOIN (SELECT t.item_id,
                   MAX(t.click_dt) AS max_date
              FROM YOUR_TABLE t
          GROUP BY t.item_id) y ON y.item_id = x.item_id
                               AND y.max_date = x.clicked_dt
    

    Alternate:

    SELECT x.item_id,
           x.user_id,
           x.click_dt
      FROM (SELECT t.item_id,
                   t.user_id,
                   t.click_dt,
                   CASE
                     WHEN @item = t.item_id THEN @rownum := @rownum + 1
                     ELSE @rownum := 1
                  END AS rk,
                  @item := t.item_id
             FROM YOUR_TABLE t
             JOIN (SELECT @rownum := 0, @item := 0) r
         ORDER BY t.itemid, click_dt DESC) x
     WHERE x.rk = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a database that is setup sort of like this (simplified, and
I have a css table setup like this: <div class='table'> <div> <span>name</span> <span>details</span> </div>
I have a table named sessions setup like this: ################################# # set # timestamp
I have a table setup like below. Table comment_flags user_id comment_id I allow users
I have a table setup like this: <table> <thead> <th> <input type=checkbox class=check-all />
I have a MySQL table, setup like this: id | game_type | votes 01
I have a bill of materials table that is set up like this: item
I have created a GUI that will setup the pivot table. For example, I
I have a table set up to hold folders. Each folder has an ID
I currently have database setup like so: CREATE TABLE `article` ( `id` int(11) NOT

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.