Query to retrieve information from a foreign key

Asked

Viewed 36 times

0

I own a table that makes relationship between two foreign keys

TABELA DE RELACIONAMENTO

I would like to do a query where I would check the fk_user_1 and get the information from fk_user_2

I did that QUERY:

SELECT users.username, users.name, users.user_id FROM friendship AS f INNER JOIN users WHERE f.fk_user_1 = 1

But this returns data duplicates of USER and also brings the USER of foreign key 1, which was what was made the comparison fk_user_1 = 1

1 answer

1

Can only get information from fk_user_2 without been duplicate the data with that QUERY:

SELECT users.username, users.name, users.user_id FROM friendship AS f INNER JOIN users WHERE fk_user_1 = 1 AND f.fk_user_2 = user_id

Browser other questions tagged

You are not signed in. Login or sign up in order to post.