Skip to content
Advertisement

Select one of two columns based on their value in SQL

I have a scenario where I have a users table where users are connections to each other based on the connections table. The connections table has a user_id1 field and a user_id2 field.

I want to get the connections for a specific user:

But the user_id’s of the connections are separated into two columns. How can I get the connections of the specific user in one one column.

I’ve tried this but it didn’t work:

Advertisement

Answer

Use a CASE expression:

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