mysql - Combine two tables and change user id to user name -


i have problem (first problem have hard time understand how sql joins work ;)

but have 2 tables, 1 user_id´s , user_names, , have table "connection", users can follow each other.

and want change query usernames second table, connection.

here sqlfiddle http://sqlfiddle.com/#!9/1779d/4

and i'm been trying this:

select users_followers.user_id,   usernames.username    users_followers join users usernames on users_followers.follower_id = usernames.id 

but no luck.

so select user_id, follower_id users_followers follower_id = 1 gives me

+---------+-------------+ | user_id | follower_id | +---------+-------------+ |       3 |           1 | |       4 |           1 | |       5 |           1 | +---------+-------------+ 

but want

+---------+-------------+ | user_id | follower_id | +---------+-------------+ | steve   | demo        | | adam    | demo        | | frank   | demo        | +---------+-------------+ 

help appreciated!

you need join user table twice as

select u1.user_name user_name, u2.user_name follower_name users_followers uf join users u1 on u1.user_id = uf.user_id join users u2 on u2.user_id = uf.follower_id 

Comments