简体   繁体   English

联接并显示一个表中的2列被另一个表引用

[英]Join and Display 2 Columns from One Table refer by Another Table

I have 2 table 我有2张桌子

Columns inside table_A : data, id_A, id_B, status table_A内的 :数据,id_A,id_B,状态

在此处输入图片说明

Columns inside table_B : id, username table_B内的 :ID,用户名

在此处输入图片说明

I want to display username from table_B reference from columns inside table_A (id_A & id_B) and make the alias id_A as User_1 and id_B as User_2 我想从table_A(id_A和id_B)内的列中的table_B引用中显示用户名,并将别名id_A设置为User_1,并将id_B设置为User_2

I has been working with INNER JOIN but it still make me confused 我一直在与INNER JOIN合作,但仍然让我感到困惑

Can you try this... 你可以试试这个吗...

SELECT a.username as User_1, b.username as User_2 FROM
table_A t
JOIN table_B b on b.id = t.id_B
JOIN table_B a ON a.id = t.id_A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两列引用另一个表中的一个ID - Two columns refer to one id in another table 将一个表的两列连接到另一表的一列 - Join two columns from one table to one column from another PHP连接两个表,其中一个表中的两列包含from_ID和to_ID引用另一表中的id - PHP join two table where two column in one table contains from_ID and to_ID refer to id in another table 如何将一列连接到另一个表中的所有列 - how to join one column to all columns from another table 如何显示来自另一个表的连接表? - How to Display Join table from another table? 如何将一个表中的两个或更多列与另一个表中的一个列联接在一起,即使第一个表列中的值为NULL - How to join two or more columns from one table with one column from another table, even there are NULL values in first table columns 我想连接数据并显示一个表中的所有记录和另一个表中的一个记录 - I want to join data and display all records from one table and just one record from another table 将一个表中的多个列连接到另一个表中的单个列 - Join multiple columns from one table to single column from another table 汇总一个表,其中列与另一张表匹配,并将结果联接 - Sum one table where columns match another table and join the results 将一个表行与mysql中的另一个表列连接起来 - Join one table rows with another table columns in mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM