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 Link to comment https://forums.phpfreaks.com/topic/91732-where-do-i-put-this-little-bit/ 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"; Link to comment https://forums.phpfreaks.com/topic/91732-where-do-i-put-this-little-bit/#findComment-469866 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! Link to comment https://forums.phpfreaks.com/topic/91732-where-do-i-put-this-little-bit/#findComment-469874 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. Link to comment https://forums.phpfreaks.com/topic/91732-where-do-i-put-this-little-bit/#findComment-469932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.