npsari Posted February 18, 2008 Share Posted February 18, 2008 I have this little php code in which, i join two tables $qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id FROM category c LEFT JOIN topic t ON t.topic_category_id = c.category_id ORDER BY c.category_id ASC"; I want to add this bit COUNT(t.topic_category_id) as CNT Where do i put it in the above code Wherever i add it, the query does not work completely i tried for example $qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id COUNT(t.topic_category_id) as CNT FROM category c LEFT JOIN topic t ON t.topic_category_id = c.category_id ORDER BY c.category_id ASC"; It doesnt work Quote Link to comment Share on other sites More sharing options...
soycharliente Posted February 18, 2008 Share Posted February 18, 2008 That's because you need a comma right before it to separate it from the previous select. $qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id, COUNT(t.topic_category_id) as CNT FROM category c LEFT JOIN topic t ON t.topic_category_id = c.category_id ORDER BY c.category_id ASC"; Quote Link to comment Share on other sites More sharing options...
npsari Posted February 18, 2008 Author Share Posted February 18, 2008 i tried that (adding the comma) however, everything dissapeards! Quote Link to comment Share on other sites More sharing options...
soycharliente Posted February 18, 2008 Share Posted February 18, 2008 I only saw that one problem (this missing comma). I don't know enough about JOIN to be able to help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.