Example Tables:
Table: TAB1
Col1 | Col2 | Col3 | Col4 |
---|---|---|---|
A1 | A2 | AA1 | G1 |
A1 | A2 | AA1 | G2 |
Table: TAB2
Col1 | Col2 | Col3 | Col4 |
---|---|---|---|
A1 | A2 | AA1 | H1 |
A1 | A2 | AB1 | H2 |
How to write a query to get Expected Result as:
Col1 | Col2 | Col3 | Col4 | Col5 |
---|---|---|---|---|
A1 | A2 | AA1 | G1 | H1 |
A1 | A2 | AB1 | G2 | H2 |
I tried join but i was getting duplicate values
How to write a query to get Expected Result as:
Col1 | Col2 | Col3 | Col4 | Col5 |
---|---|---|---|---|
A1 | A2 | AA1 | G1 | H1 |
A1 | A2 | AB1 | G2 | H2 |
3
Answers
The concept you are looking for is called equi-join
The following code should work
Please use this query.
consider generating and joining on row number
https://dbfiddle.uk/vaLEwV7A