Help write SQL query for counting
I have 2 tables as follows:
tags: id, version, name
tag_links: id, version, tag_id (foreign key to tags.id)
I need to write a SQL statement that returns how many times each tag_id occurs in the tag_links table.
For example:
tags:
id version name
-- ------- ------
1 1 sport
2 1 comedy
tag_links:
id version tag_id
-- ------- ------
1 1 1
2 1 1
3 1 1
4 1 2
5 1 2
As a result, I need:
tag_id times_occurred
------ --------------
1 3
2 2
I have little knowledge of SQL and I tried to write it, but :(
Thank.
+2
source to share