gevensen Posted December 31, 2009 Share Posted December 31, 2009 is it possible to do a multiple group query such as below I get all returned in one group with different fund accounts and projects no group is made? SELECT sum(amount), bank_account, fund, account, project FROM sc_allocated_funds WHERE expense_id IS NOT NULL GROUP BY fund AND account AND project Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/ Share on other sites More sharing options...
premiso Posted January 1, 2010 Share Posted January 1, 2010 It all depends on the structure of the data, but I think your GROUP BY is flawed, not sure if AND is valid syntax? GROUP BY fund, account, project I think commas need to be used. I am not 100% sure on that but yea. If there is a unique field being returned then the group by will not work. Such as the primary key etc. If the all the items are not unique then it should work and group them. Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/#findComment-986624 Share on other sites More sharing options...
gevensen Posted January 1, 2010 Author Share Posted January 1, 2010 i get mysql error with commas Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/#findComment-986741 Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2010 Share Posted January 1, 2010 We cannot really help you with the mysql error you got unless you post it. Posting the current query would help as well. The GROUP BY term that premiso posted is correct syntax. Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/#findComment-986776 Share on other sites More sharing options...
gevensen Posted January 1, 2010 Author Share Posted January 1, 2010 ok my mistake i changed sum(amount) to amount in the 1st part and it only showed the 1st line out of 8 SELECT amount, bank_account, fund, account, project FROM sc_allocated_funds WHERE expense_id IS NOT NULL GROUP BY fund , account , project when I changed it back to sum(amount) it worked, maybe when i did it the other day manually i hit a wrong digit as myphp admin sql is small even on my 28 in monitor SELECT sum(amount), bank_account, fund, account, project FROM sc_allocated_funds WHERE expense_id IS NOT NULL GROUP BY fund , account , project much thanks for the help the AND was wrong and the comma was right! Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/#findComment-986790 Share on other sites More sharing options...
gevensen Posted January 1, 2010 Author Share Posted January 1, 2010 as i would have written on a afto form 349 in the military many moons ago "short between headset repaired short" Quote Link to comment https://forums.phpfreaks.com/topic/186794-multiple-group-query/#findComment-986792 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.