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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:23:48+00:00 2026-05-29T22:23:48+00:00

So I have a table with three columns – col1 , col2 and col3

  • 0

So I have a table with three columns – col1, col2 and col3. I need to select those values of col1 that share rows with only one combinarion of col2 and col3. In ideal world I would write this:

SELECT col1 FROM table
GROUP BY col1
HAVING COUNT(DISTINCT(col2, col3)) = 1

How to do that in the real world?

So far I have two solutions – group by col1 and col2 and by col1 and col3 them join results; or group by all three then group that by col1. Unfortunately I get (very) different wor counts.

The database is on SQL Server 2005.

  • 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-29T22:23:49+00:00Added an answer on May 29, 2026 at 10:23 pm
    SELECT col1
    FROM table
    GROUP BY col1
    HAVING MAX(col2) = MIN(col2) AND MAX(col3) = MIN(col3)
    

    More complex:

    SELECT col1
    FROM
        (
        SELECT
            col1, 
            ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2, col3) as rn
        FROM table
        ) T
    GROUP BY col1
    HAVING MAX(rn) = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has three different date columns, so I set each
I have a table that has three columns: Category, Timestamp and Value. What I
I have a table that has three columns: myColumn, myColumn2 and myColumn3. The three
I have a table with three rows and three columns. How can I combine
I have a table ABR with three columns: two lookup values, A and B
I have a table entries with three columns: id, name, display_name . I need
I have a table that contains three columns. column1 column2 column3 mytestdata test myotherdata
I have a SQL table with three columns X, Y, Z. I need to
Assume that I have one big table with three columns: user_name, user_property, value_of_property. Lat's
I have a table with three columns: user varchar, status varchar , rep int

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.