i have the following table :
id tag1 tag2 tag3
1 apple orange pears
2 orange apple pears
3 pears orange apple
4 orange apple pears
5 apple orange orange
I want to get this
tag count
orange 6
apple 5
pears 4
I cannot make my query works
$res = mysql_query("SELECT tag, count(tag) occurrences
FROM
(
SELECT col, tag
FROM $tbl_name
unpivot
(
tag
for col in (tag1, tag2, tag3)
) unpiv
) d
GROUP BY tag
order by occurrences desc");
It basically output nothing....there is an error somewhere.