简体   繁体   中英

How to relate tables in PhpMyAdmin

So I have two different tables and I want to relate those tables. users and friends ... AND that why I came here, to find an answer :)

Users Table:

Users Table http://3.1m.yt/_p1s7MC.png

Friends table:

Friends table http://2.1m.yt/CVMMWmB.png

(I need 10 reputations to post imgs so don't even talk about).

You can related users and friends this way

select a.user_id, b.firstname, b.lastname, b.username, a.friend_id ,
        c.firstname, c.lastname, c.username
from Friends as a 
inner join users as b b.id = a.user_id
inner join users as c c.id = a.friend_id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM