I have a table P with person1id and person2id columns, and a table J with each person's personId and their name columns. I want to have a query that generates a table of person1id, person2id, name1, name2 columns. In the result, name1 is the name of person1id, name2 is the name of person2id. Is it possible to do this via nested query?
The tables look like below
table P
| person1id | person2id |
|---|---|
| p1_1 | p2_1 |
| p1_2 | p2_2 |
table J
| personId | name |
|---|---|
| p1_1 | name1 |
| p1_2 | name2 |
| p2_1 | name3 |
| p2_2 | name4 |
The expected result looks like
| person1id | person2id | name1 | name2 |
|---|---|---|---|
| p1_1 | p2_1 | name1 | name3 |
| p1_2 | p2_2 | name2 | name4 |