Pablo
Pablo

Reputation: 29519

How to left join count?

select DISTINCT(cctv_id), cctv.[name] from points_cctv left join cctv on points_cctv.[cctv_id] = cctv.[id]

I want to count number of records in points_cctv where points_cctv.[cctv_id] = cctv.[id] and show this as additional column in the above query. When I insert count(points_cctv.[cctv_id]) it will give me just one row.

Upvotes: 0

Views: 49

Answers (1)

Greg Oks
Greg Oks

Reputation: 2730

select cctv_id, cctv.[name], count(cctv_id)
from points_cctv left join cctv on points_cctv.[cctv_id] = cctv.[id]
group by cctv_id, cctv.name

Upvotes: 1

Related Questions