Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL  need to add GROUP BY State  to existing query

Posted on 2014-03-11
4
Medium Priority
?
465 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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