简体   繁体   中英

Get all tags with usage weight

I'm creating a custom tag system with php and mysql, using the Toxi mysql schema http://forge.mysql.com/wiki/TagSchema#Toxi (three tables, many to many realtionship).

I've seen a lot of examples how to retrieve most used tags, etc etc. ex.g

SELECT tag_text, COUNT(*) as num_items
FROM Item2Tag i2t
INNER JOIN Tags t ON i2t.tag_id = t.tag_id
GROUP BY tag_text;

But I need to retrieve all the tags in the system (instead of only the used ones), having the usage weight for each, and having the tags not used yet with a weight of zero.

try the following query, i will get all the tags in Tags table

SELECT tag_text, COUNT(i2t.tag_id) as num_items
FROM Tags t
LEFT JOIN Item2Tag i2t ON i2t.tag_id = t.tag_id
GROUP BY tag_text;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM