matt
matt

Reputation: 11

In some way to calculate the number of entries in tags?

tags:

id, name
---------
1   tag1
2   tag2
3   tag3 
4   tag4 

tags_id:

id_tags, id_post
--------------
1          1    
2          3    
3          1   
4          2   

how to as to count how many posts tags?

I need a mysql query..

I have a problem with that and I'm a beginner

Upvotes: 0

Views: 62

Answers (3)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

Try the following query:

SELECT tags_id.id_tags, tags.name, COUNT(id_post) AS post_count 
FROM tags_id
INNER JOIN tags ON tags_id.id_tags = tags.id
GROUP BY tags_id.id_tags
ORDER BY post_count DESC

Upvotes: 0

Koshinae
Koshinae

Reputation: 2320

See @gontrollez for an answer about getting "How many posts are there per tag".

To answer "How many tags every post has", see:

SELECT id_post, COUNT(id_tags) AS id_tags_per_post_count 
FROM tags_id 
GROUP BY id_post
ORDER BY 2, 1

Upvotes: 0

gontrollez
gontrollez

Reputation: 6548

SELECT id_tags, count(id_post) as id_post_count 
FROM tags_id 
GROUP BY id_tags

Upvotes: 1

Related Questions