简体   繁体   中英

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

i have below structure for user_match_list table

在此处输入图像描述

and this is users table

在此处输入图像描述

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

It sounds like you want two join 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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM