Created
May 16, 2013 01:33
-
-
Save jcamachott/5588772 to your computer and use it in GitHub Desktop.
Sub query counts
This file contains hidden or 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
// table called categories, with an id and a parent_category_id | |
// useful for counting number of subcategories per parent category | |
SELECT *, | |
(SELECT count(*) FROM categories c1 where c1.id=categories.parent_category_id) | |
as TheCount FROM `categories` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment