简体   繁体   English

Mysql需要从table1中获取一列两次,然后通过table2的两个不同列对它们进行排序

[英]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.

相关问题 MySQL-用table2和table3中的两列的AVG联接table1的列 - MySQL - JOIN columns of table1 with AVG of two columns from table2 and table3 将表1中的多个列合并到表2中的一列 - merging multiple Columns from table1 into one column in table2 SQL查询...我需要从表1的同一列中插入2个值到表2的2个不同列中 - SQL query…I need to insert 2 values from same column of table1 to 2 different columns of table2 新表中有两列(table1 join table2),它们具有相同的列名,如何分别获取两者的值 - There are two columns in the new table(table1 join table2) which have the same column name, how to get the values of both respectively Mysql + 将一列(table1)的数据复制到(table2)的列 - Mysql + copying data of one column(table1) to column of (table2) PHP / MySQL-尝试选择两列,其中table1中的id等于table2中的id时出现问题 - PHP/MySQL - Trouble when trying to select two columns where id from table1 is equal to id from table2 比较两个表上的列,如果table1的列与table2中的列匹配,则更新table1 - Compare columns on two tables, and update table1 if it's column matches a column in table2 在mysql中选择子查询,其中table2是table1的一列 - select subquery in mysql where table2 is one column of table1 从表1中选择数据,但需要表2作为MySQL中的条件 - select data from table1 but need table2 as condition in mysql php / mysql从表1和表2中显示列 - php/mysql SHOW COLUMNS from table1 and table2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM