我想下面的查詢顯示所有我在用戶頁面的用戶的...問題上的MySQL INNER JOIN
SELECT u.id, u.username, u.email, u.active, u.admin,
u.team_id, t.name AS team_name, sum(s.score) AS total_score
FROM users u
INNER JOIN teams t ON u.team_id = t.id
INNER JOIN stats s ON u.id = s.user_id
我有我的用戶表4級的用戶,我想列出所有,但如果我使用INNER JOIN,它只返回1行。檢查數據結構如下...
| id | game | user_id | rank | score | dnt |
+----+------+---------+-------+------+-----+
| 1 | test | 5 | 2 | 2200 |
+--------+----------+----------+-----+-----+
| 2 | test | 3 | 1 | 2500 |
+--------+----------+----------+-----+-----+
隊
| id | name | dnt |
+----+-------+-----+
| 1 | team1 | |
+----+-------+-----+
| 2 | team2 | |
+----+-------+-----+
用戶
| id | username | email | team_id |
+----+----------+-------+---------+
| 1 | user1 | | 1 |
+----+----------+-------+---------+
| 1 | user2 | | 2 |
+----+----------+-------+---------+
爲什麼'user1'和'user2'都有'id'等於'1'? – bernie