Tag cloud generation for these three tables

I have three tables for storing tags for photo albums. Here is a diagram

table 1:
Album
Album_ID Album_Name

table 2: AlbumTags
tag_id
Tag_Name

table 3: AlbumTagBridge
ID
tag_id
Album_ID

What is the most efficient SQL capable of creating a result set that looks like this:

Tag_Name | Number
Tag 1 | 19
Tag 2 | 3
Tag 3 | 17

+3
source share
2 answers
SELECT dbo.AlbumTags.Tag_Name, 
       COUNT(dbo.AlbumTagBridge.Tag_Id) AS Cnt
FROM dbo.AlbumTagBridge 
INNER JOIN dbo.AlbumTags ON dbo.AlbumTagBridge.Tag_Id = dbo.AlbumTags.Tag_ID
GROUP BY dbo.AlbumTags.Tag_Name
+2
source
Select Tag_Name, COUNT(AlbumTagBridge.ID)
From AlbumTags
Join AlbumTagBridge USING(Tag_ID)
Group By Tag_Name

AlbumTags.Tag_ID, Tag_name am (c) ( SQL- ;-), , .

0

Source: https://habr.com/ru/post/1718247/


All Articles