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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:01:37+00:00 2026-05-25T03:01:37+00:00

mySQL DB. Its a download log table. A user can download the same file

  • 0

mySQL DB. Its a download log table. A user can download the same file more than once.

I want to select the last 15 unique file downloads by a given user.

So if a users last X downloads are:

UserA, file001, 14.52
UserA, file006, 14.49
UserA, file001, 14.43-Duplicate

I want to select the last x downloads but where the filename is unique, so:

UserA, file001, 14.52
UserA, file006, 14.49

I have the code to select the last 15 downloads, but i don’t know how to apply a group by/distinct to JUST the fileName column:

SELECT `fileName`,`time` FROM `downloads`
WHERE `userName` = 'userA' 
ORDER BY `time` DESC
LIMIT 15

So how do i make sure only unique filenames are returned?

  • 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-25T03:01:38+00:00Added an answer on May 25, 2026 at 3:01 am
    SELECT `fileName`,MAX(`time`) 
    FROM `downloads`
    WHERE `userName` = 'userA' 
    GROUP BY `fileName`
    ORDER BY MAX(`time`) DESC
    LIMIT 15
    

    A GROUP BY on fileName with MAX on time (to get the last time, to get the first time use MIN) should suffice.

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

Sidebar

Related Questions

I have a huge MySQL table which has its rows encoded in UTF-8 twice.
I'm trying to query a mysql table which places its date in the following
I have a vb.net program that uses mysql as its database. And it works
I'm currently working on a PHP application that uses a MySQL database for its
MySQL column > sdate, edate ( its 2 column). sdate is start date for
On occasion, my local Rails app loses its connection to MySQL. I get some
Two libraries for Mysql. I've always used _mysql because it's simpler. Can anyone tell
I can read the MySQL documentation and it's pretty clear. But, how does one
In MySql's interpreter, it's very easy to dump a table to the screen along
I would like to download usenet messages to my personal Mysql database, so without

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.