我在mysql中有两个表。表的结构如下。
USER: userid, username
Issue: id, issue_by (userid), issue_to (userid)
我们如何为特定问题获取issue_by和issue_to的用户名?
答案 0 :(得分:0)
试试这个:
select username
from user
join issue on user.userid in (issue_to, issue_from)
where id = ?
答案 1 :(得分:0)
您需要两次加入用户表(是的,这是可能的):
SELECT i.id, u_by.username AS userby_name, u_to.username AS userto_name
FROM Issue AS i
LEFT JOIN `USER` AS u_by ON u_by.userid = i.issue_by
LEFT JOIN `USER` AS u_to ON u_to.userid = i.issue_to
理论上,您可以多次加入单个表格(没有限制)。