Skip to content
Advertisement

SQL SELECT composite primary key

I have 2 tables User1 and Relationship and it’s some kind of user-friends relationship. I need to find all the friends of a user.

For example: I have a user with ID=3 and I need to find all the users who have Relationship.STATUS = 1 with this user.

FYI, I’m a beginner in SQL, so I know it’s quite simple task but I can’t handle it.

I’ve tried to use JOIN but it wasn’t successfully.

My tables:

Advertisement

Answer

If you just want the ids then you can use conditional logic to which which of the user ids you want:

If you actually want all the user information, I would suggests exists:

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