René Fournier [EMAIL PROTECTED] wrote on 07/30/2005 02:10:02 AM:
Thanks, this is very helpful. I'm finally starting to understand
Joins. But now I have a serious performance problem. Using INNER JOIN...
SELECT users.*, COUNT(history.user_id) as num_events
FROM users
INNER JOIN history ON
Thanks, this is very helpful. I'm finally starting to understand
Joins. But now I have a serious performance problem. Using INNER JOIN...
SELECT users.*, COUNT(history.user_id) as num_events
FROM users
INNER JOIN history ON (users.id = history.user_id)
GROUP BY users.user_name
ORDER BY id DESC
Let's say I have two tables:
USERS
id name
1John
2Mary
3Sue
4Paul
5David
WINS
iduser_id
12
24
33
45
51
64
74
82
93
10 1
How can—in one SELECT statement—fetch and display all the users,
along with the number of games they each
select USERS.Name, Count(WINS.user_id)
From USERS inner join WINS on WINS.user_id = USERS.id
Group By USERS.Name
René Fournier [EMAIL PROTECTED] 7/29/05 4:40 PM
Let's say I have two tables:
USERS
id name
1 John
2 Mary
3 Sue
4 Paul
5 David
WINS
id user_id
1 2
2 4
3 3
4 5
5 1
6 4
7 4
8 2
9 3