counting records connected to specific table mysql -


i have 2 tables in mysql database called following news , views. news contain information news views contain information view , newsid. want retrieve news number of views connected it. here i've tried far, seem return 1 row.

select  n.id,  n.title,  n.image_url,  n.date, count(v.news_id) news n join views v on v.news_id = n.id 

aggregate function without group by returns 1 row, need add group by clause

select  n.id,  n.title,  n.image_url,  n.date, count(v.news_id) news n join views v on v.news_id = n.id group n.id 

Comments