0
我有3個表 - 會員,活動,新加入3代表與MySQL返回額外數據
成員表:
+--------+---------+------------+
| userid | adminid | logindate |
+--------+---------+------------+
| test6 | test3 | 03/04/2016 |
| test7 | test3 | |
+--------+---------+------------+
活動表:
+----+--------+---------+---------+
| id | userid | adminid | city |
+----+--------+---------+---------+
| 1 | test6 | test3 | Chicago |
+----+--------+---------+---------+
新表:
+----+--------+----------+
| id | userid | city |
+----+--------+----------+
| 1 | test7 | New York |
+----+--------+----------+
我想找出所有的memb屬於管理員標識(test3)的ers,無論它們是主動還是新的。 MySQL的代碼:
SELECT active.id, active.userid, active.city, members.logindate,
new.id as a, new.userid as b, new.city as c
FROM members
LEFT JOIN active
ON members.adminid = active.adminid
LEFT JOIN new
ON members.userid = new.userid
WHERE members.adminid = 'test3'
我希望會是2行的記錄:
+----+--------+---------+------------+---+-------+----------+
| id | userid | city | logindate | a | b | c |
+----+--------+---------+------------+---+-------+----------+
| 1 |test6 | Chicago | 03/04/2016 | | | |
+----+--------+---------+------------+---+-------+----------+
| | | | | 1 | test7 | New York |
+----+--------+---------+------------+---+-------+----------+
相反,我得到了:
+----+--------+---------+------------+---+-------+----------+
| id | userid | city | logindate | a | b | c |
+----+--------+---------+------------+---+-------+----------+
| 1 |test6 | Chicago | 03/04/2016 | | | |
+----+--------+---------+------------+---+-------+----------+
| 1 |test6 | Chicago | | 1 | test7 | New York |
+----+--------+---------+------------+---+-------+----------+
從第一行中的數據(從活動表)在第二行重複。我究竟做錯了什麼?感謝您的幫助。提前致謝。