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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:25:13+00:00 2026-05-22T01:25:13+00:00

I managed to make up sql query to update duplicate rows containing combinations to

  • 0

I managed to make up sql query to update duplicate rows containing combinations to null value for 2-field table. However, I am stuck with more than 2-field table.

My 2-field solution is:

Inserting test data for combinations’ table:

create table combinations as 
select 1 col1, 2 col2 from dual --row1 
union all 
select 2, 1 from dual --row2
union all 
select 1, 3 from dual --row3
union all 
select 1,4 from dual; --row4

From combinations’ table row1 and row2 are duplicate because ordering of elements doesn’t matter.

Updating duplicate combinations to null for 2 fields (updating row2 to null):

update combinations 
set col1=null, col2=null 
where rowid IN(
select x.rid from (
    select 
        rowid rid, 
        col1, 
        col2, 
        row_number() over (partition by least(col1,col2), greatest(col1,col2)
                               order by rownum) duplicate_row 
    from combinations) x 
where duplicate_row > 1);

My code above depends on least(,) and greatest(,) functions and that’s why it works neatly. Any ideas to adjusting this code to 3-field table?

Inserting test data for combinations2′ table (3-fields)

create table combinations2 as
select 1 col1, 2 col2, 3 col3 from dual --row1
union all
select 2, 1, 3 from dual --row2
union all
select 1, 3, 2 from dual --row3;

Combinations2 table with 3-fields has row1, row2, row3 which are equal. My goal is to update row2 and row3 to null.

  • 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-22T01:25:14+00:00Added an answer on May 22, 2026 at 1:25 am
    update combinations2
    set col1 = NULL
      , col2 = NULL
      , col3 = NULL
    where rowid in (
                select r 
                from
                    (
                    -- STEP 4
                    select r, row_number() over(partition by colls order by colls) duplicate_row
                    from
                        (
                        -- STEP 3
                        select r, c1 || '_' || c2 || '_' || c3 colls
                        from
                            (
                            -- STEP 2
                            select r
                                  , max(case when rn = 1 then val else null end) c1 
                                  , max(case when rn = 2 then val else null end) c2
                                  , max(case when rn = 3 then val else null end) c3
                            from 
                                (
                                -- STEP 1
                                select r
                                      , val
                                      , row_number() over(partition by r order by val) rn
                                from
                                    (
                                      select rowid as r, col1 as val
                                      from combinations2
                                    union all
                                      select rowid, col2
                                      from combinations2
                                    union all
                                      select rowid, col3
                                      from combinations2
                                    )
                                )
                            group by r
                            )
                        )
                    )
                where duplicate_row > 1
                )
    ;
    
    • step 1: sort the values in the columns
    • step 2: build rows with sorted values
    • step 3: concatenate columns to a string
    • step 4: find duplicates
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does it make sense, having all of the C#-managed-bliss, to go back to Petzold's
// get friends public Cursor getFriends(){ Cursor c = dataBase.query(SqConstants.FRIENDS_TABLE_LOCAL, null, null, null, null,
I whant to make a web interface on a server that will manage a
I managed to create a class using CodeDom and add a single method to
If I have managed to locate and verify the existence of a file using
Do you know managed tools for manipulating PowerPoint files? The tool should be 100%
I'm using managed c++ to implement a method that returns a string. I declare
Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it
I've somehow managed to get an SVN repository into a bad state. I've moved
I've managed to mostly ignore all this multi-byte character stuff, but now I need

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.