Forum Moderators: phranque
MYSQL request
I have a picture databank and for each picture, there is a list of keywords (in only one field), such as :
pic1 -> key1, key2, key3, key 4
pic2 -> key2, key3, key5
I am looking for a query to count of many times the keyword appear (or if you want an array of keywords and how often they appear)
Result for the two rows above (pic1 and pic2) should be :
key1 = 1
key2 = 2
key3 = 2
key4 = 1
key5 = 1
Thanks for your help.
Tommy
Assuming it's normalized and you have tables looking like this:
pics
pic_id int
pic_name varchar
pic_text varcharkeys
key_id int
key_descriptionpic_keys
fk_key_id int
fk_pic_id int
SELECT fk_key_id, count(*) as counts
FROM pic_keys
GROUP BY fk_key_id
ORDER BY counts DESC