Solved

MySQL  need to add GROUP BY State  to existing query

Posted on 2014-03-11
4
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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