Solved

MySQL  need to add GROUP BY State  to existing query

Posted on 2014-03-11
4
450 Views
Last Modified: 2014-03-11
The following query works well except when i try to add GROUP BY

    SELECT *
      FROM        tblEvents AS EVT
      WHERE        EVT.Online='1'  AND  (etc)    
      ORDER BY EVT.Date ASC, EVT.Time
        GROUP BY State

How to re format so i can aggregate for States together (groupings ordered alphabetically by State), then within each State, ordered by date

thank you!
0
Comment
Question by:willsherwood
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
Kent Dyer earned 500 total points
ID: 39922486
Do you have to do a SELECT *

??

It is considered poor practice to use SELECT * in your queries..  Yes, even if you have 140 columns in your table..

Group BY should be only necessary for when you use a COUNT in SQL....  Yes, you can order the result set, but when you use GROUP BY, you are going to have list out the columns to group..

HTH
0
 

Author Comment

by:willsherwood
ID: 39922504
hmmm  . . .  so there's no sub-select solution to pre-sort them by State clusters?
(sounds like i mis-used the keyword GROUP, sorry)

there are probably 23 fields out of 25 that are needed in the results (it's a very details event listing spec!)
0
 

Author Comment

by:willsherwood
ID: 39922507
so then just several levels of ORDER BY?
State ASC, Date ASC, Time ASC
0
 

Author Closing Comment

by:willsherwood
ID: 39922524
thank you!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now