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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:40:26+00:00 2026-06-06T17:40:26+00:00

I have a table similar to below in sql server 2005 date_column | field1

  • 0

I have a table similar to below in sql server 2005

date_column | field1 | field2 
1 June 2012 | xyz    | 53
1 June 2012 | abc    | 87
2 June 2012 | xyz    | 81
3 June 2012 | xyz    | 54
3 June 2012 | abc    | 53
3 June 2012 | abc    | 54
4 June 2012 | mmn    | 53
4 June 2012 | xyz    | 54
4 June 2012 | mmn    | 54
4 June 2012 | mmn    | 55
3 June 2012 | abc    | 55
3 June 2012 | adf    | 86
3 June 2012 | asd    | 33

I want to find all field1 values which has corresponding field2 values ’53’, ’54’ and ’55’. within the same date so output should be as below :

date_column | field1 | field2
3 June 2012 | abc    | 53
3 June 2012 | abc    | 54
3 June 2012 | abc    | 55
4 June 2012 | mmn    | 53
4 June 2012 | mmn    | 54
4 June 2012 | mmn    | 55

I tried the below sql code with inner join but it doesn’t work

select date_column, field1, field2 from table1
inner join (select date_column, field1, field2 from table1 where field2
in ('54',  '55')) as table2
on table1.date_column = table2.date_column and
table1.field1 = table2.field1
where field1 in ('53', '54', '55')
group by date_column, field1, field2
order by date_column, field1, field2
  • 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-06T17:40:28+00:00Added an answer on June 6, 2026 at 5:40 pm

    I believe this should work? You might be overcomplicating this or I am misunderstanding the problem

    SELECT field1, date_column FROM table1
    WHERE field2 in ('53', '54', '55')
    GROUP BY field1, date_column
    HAVING COUNT(DISTINCT field2) = 3
    

    Here is the SQLFiddle

    You say you only need to find field1, so this should work, but if you need all columns, then you can do this:

    SELECT Table1.*
    FROM Table1
    JOIN
    (
    SELECT field1, date_column FROM table1
    WHERE field2 in ('53', '54', '55')
    GROUP BY field1, date_column
    HAVING COUNT(DISTINCT field2) = 3
    ) AS MoreThan1
     ON Table1.field1 = MoreThan1.field1 and Table1.date_column = MoreThan1.date_column
    

    Here is the SQLFiddle

    OR, just add a WHERE if you only want the all columns for those in the 53-55:

    WHERE Table1.field2 in ('53', '54', '55')
    

    Another Fiddle

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

Sidebar

Related Questions

I have a sql table similar to the one below. And I want to
I have a table on another SQL server which I need to copy from
I have a table similar to the example shown below. I would like to
I have a table similar to the one below: ID Vote_Up Vote_Down Vote_Total 1
I have a table very similar to the one below. p1 and p2 on
I have a table that is similar to the following below: id | cat
I have a table with data similar to below: Group TimePoint Value 1 0
I have an SQL query similar to below: SELECT NAME, MY_FUNCTION(NAME) -- carries out
I have a table similar to this +--+-----+----+ |ID|Entry|Exit| +--+-----+----+ |18|32154|NULL| +--+-----+----+ |19|NULL |NULL|
I have a table similar to the following: id key str_val date_val num_val 1

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.