我有两个这样的表:
用户(表1)
Id name email phone role etc
-------------------------------
65 yotav y@.com 888 crm ...
20 tobi t@.com 999. User ...
Crm_lead(表2)
Id user_id lead_id
--------------------
1. 65. 85
2. 65. 20
3. 65. 65
我需要进行查询以制作下表
Id name email phone role userid(from crm_lead)
-----------------------------------------------
65 yotav y@.com 888 crm. Yotav
20 tobi. ......... Yotav
换句话说,根据CRM主管,我需要将用户的销售名称添加到用户。
我该怎么做?
答案 0 :(得分:0)
试试这个加入
SELECT b.id, b.name, b.email, b.phone, b.role, a.name
FROM Users a
JOIN Crm_lead c ON a.id = c.user_id
RIGHT JOIN Users b ON c.lead_id = b.id;