I have the following tables with the attached columns.

```
tags
 -t_id (PRIMARY)
 -pg
tag_refs
 -t_id
 -bp_id

```

Now I trying to write a MySQL query that returns the total number of tags ordered by how popular they are - which, in this case, means how many times the unique t\_id is represented in the tag\_refs table.

I assume this would be a joined query, which has to return a list from the tags table where I can use the pg column to output the name/title of each tag only once, ordered by which is used the most.

I tried the following query which returns only one row, but which seems to be ordered as I want it to be.

```
SELECT *
FROM tags
JOIN tag_refs ON tags.t_id = tag_refs.t_id
ORDER BY COUNT(tag_refs.t_id) DESC

```