Skip to content
Advertisement

How can I join the same data for different columns?

I am sstruggling to make a query to join the corresponding replacing the IDs. I have two tables USERS and CONNECTIONS.

Users:

Connections:

In Connections both columns includes the user_id from Users to represent the connection between the people. I need the result like below:

Advertisement

Answer

Joining Connections table with Users tables give the expected result.

By using U1.user_id = C.user_id to get the user and using U2.user_id = C.friend_id to get the friend values.

Demo on db<>fiddle

output:

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