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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:03:45+00:00 2026-06-14T04:03:45+00:00

I have 2 tables with values like below: tbl_users user_ID name 1 somename1 2

  • 0

I have 2 tables with values like below:

tbl_users

user_ID      name     
1          somename1   
2          somename2   
3          somename3   

tbl_interviews

int_ID     user_ID      answer          date      
 1            1         sometextaba   2012-11-04 
 2            2         sometextxcec  2012-10-05
 3            1         sometextabs   2011-06-04
 4            3         sometextxcfc  2012-11-04
 5            3         sometextxcdn  2012-11-04

how can i ask mysql tell me who is the only user in the table above that was interviewed this year but had also another interview in the previous years? the only one is the user with id = 1 (since he had an interview (the int_id 1) this year, but the first interview was in 2011 (int-id 3). )
unfortunately I’m not able even to select them..

  • 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-14T04:03:46+00:00Added an answer on June 14, 2026 at 4:03 am

    By joining the table against itself, where one side of the join only includes interviews from this year and the other side only includes previous years, the result of the INNER JOIN will be users having both.

    Because it doesn’t need to rely on any aggregates or subqueries, this method should be extremely efficient. Especially so, if the date column has an index.

    SELECT
      DISTINCT
      thisyear.user_ID,
      name
    FROM
      /* Left side of join retrieces only this year (year=2012) */
      tbl_interviews thisyear
      /* Right side retrieves year < 2012 */
      /* The combined result will elmininate any users who don't exist on both sides of the join */
      INNER JOIN tbl_interviews previous_years ON thisyear.user_ID = previous_years.user_ID
      /* and JOIN in the user table to get a name */
      INNER JOIN tbl_users ON tbl_users.user_ID = thisyear.user_ID
    WHERE
      YEAR(thisyear.date) = 2012
      AND YEAR(previous_years.date) < 2012
    

    Here is a demonstration on SQLFiddle

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

Sidebar

Related Questions

I have 3 tables with values like below **tbl_product** recID pID price colour 1
If I have table with a Date column called myDate , with values like
I have a table like ___________ | id | date | ----------- with values
Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
I have two tables like the below one in my DB. In the first
I have a multi-table SELECT query which compares column values with itself like below:
I have a situation where my DB tables are like below, I am wondering
I have two database tables with some demo data like shown below Create table
I have a table where we record per user values like money_spent, money_spent_on_candy and
I have two arrays of values like X,Y,Z and 1,2 There is a table

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.