[英]Mysql need to get one column two times from table1 and sort them by two different columns of table2
So here is the thing, I have two tables: 事情就是这样,我有两个表:
table1 has columns intUsersID, varUsersName
table1具有intUsersID, varUsersName
列
table2 has columns intCouriers, intResponsible
table2有列intCouriers, intResponsible
intCouriers
(have some numbers of intUsersID that are Couriers), and intResponsible
(have some numbers of intUsersID that are Responsible) intCouriers
(具有一些Couriers的intUsersID)和intResponsible
(具有一些负责任的intUsersID)
In my query I must see User Names of Couriers and of the Responsible persons something like that: 在我的查询中,我必须看到Couriers和负责人的用户名是这样的:
SELECT
table1.varUsersName 'Couriers',
table1.varUsersName 'Responsible'
FROM
table1
LEFT JOIN
table2 ON table2.intCouriers = table1.intUsersID
And then I need some how to subquery or join this "table1.varUsersName 'Responsible'", to get also 'Reponsible' persons. 然后,我需要一些如何子查询或加入“ table1.varUsersName'Responsible'”的方法,以同时获得“ Reponsible”人员。 Please help me. 请帮我。
Should be this 应该是这个
SELECT table1.varUsersName 'Couriers', table2.varUsersName 'Responsible'
FROM table1
INNER JOIN table3 on table1.intUsersID = table3.intCouriers
INNER JOIN table1 as Table2 on table2.intUsersID = table3. intResponsible
SELECT Couriers.varUsersName as "Couriers",
Responsible.varUsersName as "Responsible"
FROM `table2` t2
LEFT JOIN table1 Couriers on Couriers.intUsersID = t2.intCouriers
LEFT JOIN table1 Responsible on Responsible.intUsersID = t2.intResponsible
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.