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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:59:13+00:00 2026-06-16T21:59:13+00:00

I have data in the following format: DATE DATA1 DATA2 ————————————————- 20121010 ABC DEF

  • 0

I have data in the following format:

DATE                 DATA1                 DATA2
-------------------------------------------------
20121010             ABC                   DEF
20121010             DEF                   ABC
20121010             HIJ                   KLM
20121010             KLM                   HIJ
20121212             ABC                   DEF
20121212             DEF                   ABC
20121212             HIJ                   KLM
20121212             KLM                   HIJ

What I want to do is select rows 1 and 3. I don’t care about rows 2 and 4 because they are essentially “duplicates” in my eyes.

Seems simple but I’m just trying to put the query together to accomplish this.

  • 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-16T21:59:14+00:00Added an answer on June 16, 2026 at 9:59 pm

    You can use the row_number() function for this, assuming you are using version 2005 or higher:

    select date, data1, data2
    from (select t.*,
                 row_number() over (partition by date order by date) as seqnum
          from t
         ) t
    where seqnum = 1
    

    The expression order by date should produce an arbitrary ordering in any database that supports row_number. In SQL Server, you can also use order by (select NULL).

    Or, I realize that your question may be about eliminate duplicates, regardless of order. For that, you can do:

    select distinct date, minData, maxData
    from (select t.date,
                 (case when data1 > data2 then data1 else data2 end) as minData,
                 (case when data1 > data2 then data2 else data1 end) as maxData
          from t
         ) t
    

    This might, however, rearrange the two values, when only one row appears.

    The more complicated solution to maintain the original ordering of the columns and eliminate the additional rows combines the two approaches:

    select date, data1, data2
    from (select t.*,
                 row_number() over (partition by date order by minData, maxData) as seqnum
          from (select t.*
                       (case when data1 > data2 then data1 else data2 end) as minData,
                       (case when data1 > data2 then data2 else data1 end) as maxData
                from t
               ) t
         ) t
    where seqnum = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have a log of following format << [ABC] some other data some other
I have some data in the following format: date x 2001/06 9949 2001/07 8554
I have date data being returned from a server in the following format through
I have the following data frame: id<-c(1,1,1,3,3,3) date<-c(23-01-07,27-01-07,30-01-07,11-12-07,12-12-07,01-01-08) df<-data.frame(id,date) df$date2<-as.Date(as.character(df$date), format = %d-%m-%y) id
I have a log table with the following format (and sample data): date |
I have an hourly weather data in the following format: Date,DBT 01/01/2000 01:00,30 01/01/2000
I have soccer results data in the following format (thousands of observations): Div date
I have a CSV file in the following format: id,code,date,address,complete_url Example data from the
I have data in the following format: 4:How do you do? 10:Happy birthday 1:Purple

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.