| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Soon to be RICHdoggie! | Mysql counting query: I currently have this mysql query: Code: SELECT c.*, s.* FROM categories c, subcategories s WHERE c.cat_id=s.cat_id GROUP BY c.cat_id ORDER BY c.cat_name ASC ). in the table "subcategories" I have "cat_id" which is linked to the categories table, "subcat_id" which isn't really of any use in this script, and "subcat_name". in the "categories" table I have "cat_name" and I have "cat_id".How would I go about doing it? Thanks Tom |
| |
| | #2 (permalink) |
| NamePros Member | Not feeling very SQLey tonight, but is this anything close to what you want? SELECT c.cat_name, COUNT(s.subcat_name) FROM category c, subcategory s WHERE c.cat_id = s.cat_id GROUP BY c.cat_name Andy
__________________ Coming soon - POCHost.com |
| |
| | #4 (permalink) |
| NamePros Member | Just tried this, it will give you a list of cats and the number of subcats in each. Guess I didn't understand the question!! Andy
__________________ Coming soon - POCHost.com |
| |
| | #6 (permalink) | |
| An American Soldier ![]() | Quote:
its the best way... less space, less bandwidth...
__________________ Completely Free cPanel Hosting -- Deployed to Afghanistan -- "There is no such thing as rich over-night unless you owned Google stock in 2006" | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |