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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:13:34+00:00 2026-06-08T18:13:34+00:00

everyone. I’m new here and I have a question on SQL which I seem

  • 0

everyone. I’m new here and I have a question on SQL which I seem to think that it may be easy to do in SQL but I’m out of ideas and I could use some help with my problem.

So I have a table (sql also here http://www.sqlfiddle.com/#!2/b9a37/1/0)

With multiple occurences for each person, different id’s with auto increment and I have 3 fields, “Category”, “In” and “Out”

What I’m trying to implement is a way for me to know when some of the users on the table belongs to the system using the “In” and “Out” as the limits.

Example

  • User A – Category A – IN 2002 OUT 2010
  • User A – Category B – IN 2011 OUT 9999
  • User B – Category B – IN 2002 OUT 2010

In the above example I would like to know who belongs to the system in year 2010:

so for User A, he Left Category A in 2010 but joined in 2011 Category 2011 so he SHOULD be a user in 2010 with Category A

for User B he should NOT belong to the system because there’s no new entry for 2010+

At the end I’m tring to have the following output for 2010

  • Smith Category A
  • Pablo Category A

I’m not achieving the results I want, for example

SELECT * from users
WHERE (users.In<=2010 and users.Out=2010)

Outputs

  • Smith Category A In 2002 Out 2010
  • Roger Category B In 2002 Out 2010
  • Miller Category B In 2008 Out 2010
  • Pablo Category A In 2002 Out 2010

But Roger and Miller left the system in 2010 so they should NOT be members in 2010, and Smith and Pablo changed their category in 2010+ so they should show in the output.

A few notes:
Don’t ask me why this solution is developed like this, I just stumbled on it and trying to solve this issue.
I’m considering doing a function in php do filter the data based on the requirements that I want because i’m running out of ideas to solve this.
If you find a way to implement this better than what I saw here, be my guest and i’m open to new ideas.

Thanks in advance.

Final Note:
Perhaps using http://www.sqlfiddle.com/#!2/b9a37/1/0 and try to find the desired output will help you out.

  • 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-08T18:13:36+00:00Added an answer on June 8, 2026 at 6:13 pm

    Give this one a shot:

    select Name, Category
    from users
    where `In` <= 2010 and (
            `Out` > 2010 or name in (
                select name
                from users
                where `In` = 2011
                )
            )
    

    SQL Fiddle Example

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

Sidebar

Related Questions

Everyone, I am a newbie to android development. Now I have a question that
Everyone, I have really tried, but I can't find out how to upload photos
everyone! new to here and been pondering about this myself for some times with
everyone. Here is a small VBA (Excel) function that i wrote, full of MsgBoxes
everyone The problem is if there exists two exported components which have the same
everyone. I'm new here and this is my first post. I'm creating a simple
everyone. I have a string like this String message = This is the new
everyone, I have some question about C++, what do You actually prefer to use
everyone -- I have a Heisenbug, here (only shows up with debugger detached!). Seems
everyone. I have problem replacing existing rows in table with new ones. I use

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.