Skip to content
Advertisement

Oracle SQL: Transfer certain records from one table to another filtering rows based on condition

Need to transfer certain records of some columns from Table1 to Table2 but filtering rows based on condition.

Lets say Table1 looks like as shown below, has many columns in it.

In Table2, need to insert rows from Table1 based on following:

First, select A, B, C, D, E, F from Table1 where D='xyz' and E=1; and on the result of this query apply the following condition to further filter out unwanted rows:

Condition: For same values in columns B, C, D & E in 2 different rows, if column F has 2 different values then only keep the row with greater value in column A.

So desired output in Table2 is shown as below:

How can this be achieved through the simplest and most efficient SQL query?

Any help will be appreciated.

Advertisement

Answer

You can use window functions:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement