Solved

MySQL  need to add GROUP BY State  to existing query

Posted on 2014-03-11
4
449 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mysqli Query 5 41
mySql Syntax 7 32
query help 18 51
MySQL: Updating SubQuery Match Faster 9 16
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 article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

26 Experts available now in Live!

Get 1:1 Help Now