我試圖根據表中的member_id
,parent_id
和sponsor_id
表從表「member」中提取parent_name和sponsor_name。加入兩個Mysql表來獲取多列的名稱
我試過下面的查詢,但我不知道爲什麼它不起作用。
SELECT mt.member_id, mt.parent_id, mt.sponsor_id, mt.member_name, m.member_name as parent_name , m1.member_name as sponsor_name
FROM `member_tree` mt
LEFT JOIN `member` m ON mt.parent_id = m.member_id
LEFT JOIN `member` m1 ON mt.sponsor_id = m1.member_id
WHERE mt.`member_id` IN (1000015,1000016,1000017,1000018,1000019,1000020,1000021,1000022,1000023,1000024,1000025,1000026,1000027,1000028,1000029,1000030)
謝謝。
嘗試m.member_id = mt.parent_id。也請先試着用單行來理解查詢 – Nes