Reputation: 21391
I'm not very good at database queries. Need help with what is probably a simple query.
Database: MYSQL
zip | city | state
post_id | title | post | zip
I need to display the number of posts for each unique city.
Upvotes: 1
Views: 73
Reputation: 1895
I would do it this way. This would display the city name in the output and also show teh cities for which there are no posts exist.
SELECT city,count(*) as "num_posts" FROM zipcodes LEFT JOIN post ON post.zip = zipcodes.zip GROUP BY city;
Upvotes: 0
Reputation: 58949
SELECT count(*) FROM post LEFT JOIN zipcodes ON post.zip = zipcodes.zip GROUP BY city;
Upvotes: 3