Folgendes Problem:
Ich hab 2 tabellen (td_group und td_users)
ich will jetzt (mit einem befehl) alle gruppen ausgeben und die anzahl der user die drin sind.
soweit so gut, alles geht, nur leider fehlt eine gruppe (0 user drin, genauso wie eine andere)
users hat 3 zeilen
gruppen 4
hoffe jemand findet mein denkfehler
Ich hab 2 tabellen (td_group und td_users)
PHP-Code:
mysql> desc td_users;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(255) | | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| passwort | varchar(255) | YES | | NULL | |
| groupid | int(255) | YES | | NULL | |
| mail | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
PHP-Code:
mysql> desc td_group;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(255) | | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| can_edit_group | tinyint(1) | YES | | NULL | |
| can_edit_todo | tinyint(1) | YES | | NULL | |
| can_add_group | tinyint(1) | YES | | NULL | |
| can_del_group | tinyint(1) | YES | | NULL | |
| can_add_todo | tinyint(1) | YES | | NULL | |
| can_del_todo | tinyint(1) | YES | | NULL | |
| can_view_todo | tinyint(1) | YES | | NULL | |
| can_add_user | tinyint(1) | YES | | NULL | |
| can_del_user | tinyint(1) | YES | | NULL | |
| can_edit_user | tinyint(1) | YES | | NULL | |
| can_sedit_user | tinyint(1) | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
13 rows in set (0.00 sec)
PHP-Code:
Select g.id,count(u.id) as anzahl,g.name from td_group as g LEFT JOIN td_users as u on u.groupid = g.id group by u.groupid;
users hat 3 zeilen
gruppen 4
hoffe jemand findet mein denkfehler
Kommentar