Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 将两列与另一个表的相同字段联接_Mysql_Sql - Fatal编程技术网

Mysql 将两列与另一个表的相同字段联接

Mysql 将两列与另一个表的相同字段联接,mysql,sql,Mysql,Sql,我对从用户表中获取发送方和接收方名称的mysql查询有一个问题 下面是用户匹配列表的结构 这是users表 我想将senderId与用户表联接,并将firstname+lastname作为senderName 与receiverId相同,获取名称作为receiverName 请引导我 谢谢听起来你想要两个加入s: select uml.*, concat(us.firstname, ' ', us.lastname) as sendername, concat(u

我对从用户表中获取发送方和接收方名称的mysql查询有一个问题

下面是
用户匹配列表的结构

这是
users

我想将senderId与用户表联接,并将firstname+lastname作为senderName 与receiverId相同,获取名称作为receiverName 请引导我
谢谢

听起来你想要两个
加入
s:

select uml.*,
       concat(us.firstname, ' ', us.lastname) as sendername,
       concat(ur.firstname, ' ', ur.lastname) as receivername,
from user_match_list uml join
     users us
     on uml.sendid = us.id join
     users ur
     on uml.receiverid = ur.id;

应使用两个联接:

SELECT us.firstName + ' ' + us.LastName,
       us2.firstName + ' ' + us2.LastName
FROM dbo.user_match_list AS um
INNER JOIN dbo.Users AS us ON um.senderId = us.Id
INNER JOIN dbo.Users AS us2 ON uml.receiverId = us2.Id
看见