469,148 Members | 1,316 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

Howto put these two queries together?

Howto put these two queries together?

sql = "SELECT DISTINCT medium_id, COUNT(tag) AS count FROM tags WHERE
tag = 'test' GROUP BY medium_id ORDER BY count DESC"

This query is working.

Id like to try something like

sql = "SELECT * FROM media WHERE id IN (SELECT DISTINCT medium_id FROM
tags WHERE tag = 'test')"

But how can I order the resut by quantity (counts of tag)?

Thank you for help.
//BEN

May 25 '06 #1
1 2189
Benny Schudel wrote:
Howto put these two queries together?
sql = "SELECT DISTINCT medium_id, COUNT(tag) AS count FROM tags WHERE
tag = 'test' GROUP BY medium_id ORDER BY count DESC"
sql = "SELECT * FROM media WHERE id IN (SELECT DISTINCT medium_id FROM
tags WHERE tag = 'test')"


SELECT m.*, COUNT(*) AS count
FROM media AS m JOIN tags AS t ON m.id = t.medium_id AND t.tag = 'test'
GROUP BY m.id
ORDER BY count DESC

Assuming m.id is a unique key for the media table.

Regards,
Bill K.
May 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Mike N. | last post: by
9 posts views Thread by Dom Boyce | last post: by
5 posts views Thread by listerofsmeg01 | last post: by
1 post views Thread by JosAH | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.