Created
April 15, 2010 14:32
-
-
Save eet-nu/367147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT tags.*, taggings.count | |
FROM tags | |
JOIN ( | |
SELECT | |
taggings.tag_id, | |
count(*) as count | |
FROM taggings | |
INNER JOIN companies ON companies.id = taggings.taggable_id | |
AND taggings.taggable_type = 'Company' | |
AND `companies`.`visible` = 1 | |
AND `companies`.`closed` = 0 | |
AND `companies`.`registration` = 0 | |
JOIN taggings companies_taggings_dutch_230 | |
ON companies_taggings_dutch_230.taggable_id = companies.id | |
AND companies_taggings_dutch_230.taggable_type = 'Company' | |
AND companies_taggings_dutch_230.tag_id = 47 | |
GROUP BY taggings.tag_id | |
HAVING COUNT(*) > 0 | |
) AS taggings ON taggings.tag_id = tags.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment