[英]join two column with same field of another table
i have one issue with mysql query to fetch name of sender and receiver from user table我对 mysql 查询有一个问题,从用户表中获取发送者和接收者的名称
i have below structure for user_match_list
table我有以下
user_match_list
表的结构
and this is users
table这是
users
表
i want to join senderId with user table and get firstname + lastname as senderName same as for receiverId and get name as receiverName please guide me thanks我想将 senderId 与用户表一起加入,并获得 firstname + lastname 作为 senderName 与 receiverId 相同,并将 name 作为 receiverName 请指导我谢谢
It sounds like you want two join
s:听起来你想要两个
join
:
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;
You should use two joins:您应该使用两个连接:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.