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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:59:10+00:00 2026-05-26T17:59:10+00:00

Imagine the below table as A col1 col2 col3 rank 1 2 n 5

  • 0

Imagine the below table as A

col1 col2 col3 rank
 1     2   n    5
 1     2   n    6
 2     3   a    3

While inserting below records from table B to table A, the rank column valus should be keep incrementing if the same records inserts.

Records in table B which gonna insert into A are

col1 col2 col3
 1     2    n
 2     3    a

The desired output in table A after the above records are inserted is,

 col1 col2 col3 rank
   1    2   n    5
   1    2   n    6
   1    2   n    7
   2    3   a    3
   2    3   a    4

Please help me how to acheive this.Thanks.

  • 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-26T17:59:11+00:00Added an answer on May 26, 2026 at 5:59 pm

    If the record in B are unique, then you could use a query like this

    ————–EDIT——————-

    If B can have multiple records, you can use row_number() funcion with partition

    insert into TestA
    select b.*, 
    (select max([rank]) from TestA where col1 = b.col1 and col2 = b.col2 and col3 = b.col3) 
    + row_number()over (partition by col1, col2, col3 order by col1, col2,col3 asc) as N
     from TestB b
    

    ————–END EDIT——————-

    Note: i renamed the table: TestA and TestB

    insert into TestA
    select b.*, (select max([rank])+1 from TestAwhere col1 = b.col1 and col2 = b.col2 and col3 = b.col3)
     from TestB b
    

    or with a JOIN like this

    insert into testa
    select b.*, mr+1 from TestB b
    join
    (select col1, col2, col3, max([rank]) as mr
    from TestA A
    group by col1, col2, col3) as M
    on 
    b.col1 = M.col1 and b.col2 = M.col2 and b.col3 =M.col3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine a table (table1) with one column (column1) and one record whose value is
The code below echoes out an HTML table, populated with values from a MySQL
The below code is from google analitycs api. I can imagine some of the
I'm looking for example of how I would solve the scenario below: Imagine my
Imagine the following table (called TestTable ): id somedate somevalue -- -------- --------- 45
Imagine I have a table which stores a series of sparse vectors. A sparse
The two posts below are great examples of different approaches of extracting data from
Below is my table and some queries I run that take a lot of
I need to join a table on itself while joining other tables and doing
Imagine I have array of values ranging from 1 to 24. I want to

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.