count - How many times each value from a list appears in a column in another table. MYSQL -


i have table of id values , need count how many times each of ids appears in column in table.

i have figured out how values appear @ least once:

select one.id, count(*) table1 one, table2 2 one.id = two.id group one.id; 

but can't figure out how include ids appear in first don't appear in second table @ all.

example:

table1:       table2:  +-----+      +-----+ | id  |      | id  | +-----+      +-----+ | 11  |      | 11  | | 12  |      | 12  | | 13  |      | 14  | | 14  |      | 11  | +-----+      | 11  |              | 12  |              +-----+ 

the result be:

+-----+----------+ | id  | count(*) | +-----+----------+ | 11  | 3        | | 12  | 2        | | 14  | 1        | +-----+----------+ 

i'm trying make include line | 13 | 0 |

you doing implicit inner join discouraged. instead need left join, like:

select one.id, count(two.id)  table1 1 left join table2 2  on one.id = two.id  group one.id; 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -