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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:17:44+00:00 2026-06-07T10:17:44+00:00

I am having problems understanding how best to tackle this query. I have a

  • 0

I am having problems understanding how best to tackle this query.

I have a table called user_files. A user can have many files. I want to get a list of users who have not modified any of their files within the last year. If a user has modified at least one of their files within the last year, then that user should be excluded.

  Table: user_files
  file_id | user_id | date_modified
  ----------------------------------
  1        100       2010-10-01
  2        100       2010-11-13
  3        100       2011-01-01
  4        101       2010-10-01
  5        101       2010-06-13
  6        101       2011-04-12
  7        101       2012-04-01

The expected result would only list user_id 100.

Here is some bad sql I have been playing with. The idea is that I find all users who recently modified their files and then find users who are not included in that list.

    select user_id from users where user_id not in
    (
      select user_id from 
      (
        select user_id, story_id, max(date_modified) from user_files 
        where DATE_FORMAT(date_modified, '%Y-%m-%d') >= DATE_SUB(curdate(), INTERVAL 1 YEAR)
        group by user_id
      )x
    )

Thanks

  • 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-07T10:17:45+00:00Added an answer on June 7, 2026 at 10:17 am
    SELECT DISTINCT(f.user_id)
    FROM user_files f
    WHERE NOT EXISTS(SELECT 1
                     FROM user_files ff
                     WHERE ff.user_id = f.user_id
                     AND ff.date_modified >= DATE_SUB(curdate(), INTERVAL 1 YEAR))
    

    http://sqlfiddle.com/#!2/64e7f/1

    Or,

    SELECT user_id
    FROM user_files
    GROUP BY user_id
    HAVING MAX(date_modified) < DATE_SUB(curdate(), INTERVAL 1 YEAR)
    

    http://sqlfiddle.com/#!2/64e7f/4

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

Sidebar

Related Questions

I'm having problems understanding how latest.integration works. I have an example that is not
I am relatively new to C++ and am having problems understanding struct. I have
I'm having problems with understanding how jQuery create headers for ajax post. I have
We are having a few problems understanding how best to use NHibernate. We typically
I'm having problems understanding how a header(Location: http://www.google.com/); can work in the middle of
I'm having problems understanding the MYSQL join syntax. I can't seem to manipulate it
I'm having problems understanding how I should install xhtml2pdf. I have followed the instructions
I'm having problems understanding xslt. In my source document I have to find the
I'm having problems understanding this article: http://blog.darkhax.com/2010/07/30/auto-scale-your-resque-workers-on-heroku . I don't quite get it why
I'm having problems understanding this. It's in intel syntax cmp eax, 0x19 ja greater

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.