![](/img/trans.png)
[英]Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP
[英]MySQL several IDs in one row join with another table
我在以下堆棧中:我有2個表:Users和Follow。 用戶表包含兩列:ID和全名。 跟蹤表包含兩列:Follower_ID和following_ID。 它表明史密斯正在追隨簡。 現在,我需要一個顯示兩個用戶全名的輸出。
請幫忙!
Table Users:
ID | 1, 2
Fullname | Smith, Jane
Table Follow:
Follower_ID | 1
Following_ID | 2
要求的輸出:
Follower_ID | 1
Follower_fullname | Smith
Following_ID | 2
Following_fullname | Jane
您可以對用戶表使用兩次內部聯接
select
a.Follower_ID
, c.Fullname as Follower_Fullname
, a.Following_ID
, b.Fullname as Following_Fullname
from Follow as a
inner join Users as b on b.ID = a.Following_ID
inner join Users as c on c.ID = a.Follower_ID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.