why this left join query failed to load all the data in left table ?

Posted by lzyy on Stack Overflow See other posts from Stack Overflow or by lzyy
Published on 2010-03-27T13:43:45Z Indexed on 2010/03/27 14:03 UTC
Read the original article Hit count: 341

Filed under:
|
|

users table

+-----+-----------+
| id  | username  |
+-----+-----------+
|   1 | tom       |
|   2 | jelly     |
|   3 | foo       |
|   4 | bar       |
+-----+-----------+

groups table

+----+---------+-----------------------------+
| id | user_id | title                       |
+----+---------+-----------------------------+
|  2 |       1 | title 1                     |
|  4 |       1 | title 2                     |
+----+---------+-----------------------------+

the query

SELECT users.username,users.id,count(groups.title) as group_count 
FROM users 
LEFT JOIN groups 
ON users.id = groups.user_id

result

+----------+----+-------------+
| username | id | group_count |
+----------+----+-------------+
| tom      |  1 |           2 |
+----------+----+-------------+

where is the rest users' info? the result is the same as inner join , shouldn't left join return all left table's data?

PS:I'm using mysql

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql