select name, count( table1_id ) from table1 left join table2 on table2.table1_id
= table1.id group by name;
Should give you the results you're looking for.
Bjoern Frantzen wrote:
> Given the following two tables;
> How can i do a select which returns all names from table1 and a count of how
> many relations there is in table2?
> When I do
> SELECT table1.name, count(table2.table1_id)
> FROM table1, table2
> WHERE table1.id = table2.table1_id
> it works except I don't get the names of those without a relation in table2.
> I would like to have them listed as well with 0 relations.