ukweb Posted July 20, 2009 Share Posted July 20, 2009 Hey peeps I'm really tearing my hair out over this one!! I am developing a system at work. One table stores motorcycles, another stores their categories. Each bike can have many categories, hence the different tables. RIGHT.... The system has to produce a stock list, and it lists bikes for each category. This is my SQL for the query to return a list of categories... $query_stock_cat_list = sprintf("SELECT vehicle_categories.name AS name FROM vehicle_categories LEFT JOIN vehicle_list ON vehicle_list.vehicle_id = vehicle_categories.vehicle_id WHERE vehicle_list.condition = %s GROUP BY vehicle_categories.name", GetSQLValueString($condition, "text")); $stock_cat_list = mysql_query($query_stock_cat_list, $sql) or die(mysql_error()); $row_stock_cat_list = mysql_fetch_assoc($stock_cat_list); $totalRows_stock_cat_list = mysql_num_rows($stock_cat_list); When I run the script it lists the categories (good times) but repeats them so the 'Group by' does not appear to be working, bad times... the returned values are below, not sure what relevance that has but will include the results anyway... Used Honda Used Honda Used European Used Honda Used European Used Japanese ANY help will be received with a lot of gratitude! Ste xx Quote Link to comment https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/ Share on other sites More sharing options...
kickstart Posted July 20, 2009 Share Posted July 20, 2009 Hi Are the category names exactly the same? Leading / trailing spaces? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/#findComment-878508 Share on other sites More sharing options...
ukweb Posted July 20, 2009 Author Share Posted July 20, 2009 Hi Are the category names exactly the same? Leading / trailing spaces? All the best Keith Hi Keith! Yes they are exactly the same, its a dropdown box that populates the category name. strange! Quote Link to comment https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/#findComment-878510 Share on other sites More sharing options...
kickstart Posted July 20, 2009 Share Posted July 20, 2009 Hi Never really used a GROUP BY like that (would just use DISTINCT) but having a quick play it looks like it works. As a quick simple check try the following:- SELECT vehicle_categories.name, COUNT(*) FROM vehicle_categories GROUP BY vehicle_categories.name All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/#findComment-878512 Share on other sites More sharing options...
ukweb Posted July 20, 2009 Author Share Posted July 20, 2009 I used distinct instead and that fixed it, ta very much! I owe you a beer :-) Quote Link to comment https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/#findComment-878573 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.