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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:21:13+00:00 2026-05-29T05:21:13+00:00

For Example, Table with three cols and data col1 col2 col3 10 20 30

  • 0

For Example, Table with three cols and data

col1  col2  col3
 10    20    30
 40    50    60
 40    50    80

Want to do a select where for the last two rows only returns one since col1 and col2 are the same.

select distinct will not work since col3 are different.

so output would be

 10 20 30
 40 50 xx (don't care)
  • 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-29T05:21:13+00:00Added an answer on May 29, 2026 at 5:21 am

    As you only have one additional column you can just use an arbitrary MIN/MAX aggregate and GROUP BY

    SELECT col1,
           col2,
           MAX(col3) AS col3
    FROM   YourTable
    GROUP  BY col1,
              col2  
    

    More generally if your RDBMS supports analytic functions you can use

    WITH T
         AS (SELECT col1,
                    col2,
                    col3,
                    ROW_NUMBER() OVER (PARTITION BY col1, col2 
                                           ORDER BY col1, col2) AS RN
             FROM   YourTable)
    SELECT col1,
           col2,
           col3
    FROM   T
    WHERE  RN = 1  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all, My requirement is simple.I want to select random rows from a table.
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London
I will explain problem with an example: There is two table in my database,
I have a three-table system: Companies, Customers, and Matches. The matches include, for example,
I have an issue with a table containing three cells in one row. Two
I have three tables kinda like the example below: TABLE CARS carId carName -----
I have a table with three NCLOB columns. For each NCLOB I want a
I have a table ABR with three columns: two lookup values, A and B
I have my table: call it tblA THis table has three rows, id ,
Here is an example table: ID time data type 0 0100 xyz 0 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.