Solved

Using Group By AND Order By in query

Posted on 2014-03-12
2
273 Views
Last Modified: 2014-03-12
I need to use GROUP BY and ORDER BY in the following query. I added Order By last_name after GROUP BY wp_users.user_login but it didn't work. Please let me know where/how to add ORDER BY last_name ASC  to this

"SELECT

                    
					 wp_users.user_login,
					MAX(CASE WHEN wp_usermeta.meta_key = 'first_name' then wp_usermeta.meta_value ELSE NULL END) as first_name,
                    MAX(CASE WHEN wp_usermeta.meta_key = 'last_name' then wp_usermeta.meta_value ELSE NULL END) as last_name
                   

                    FROM wp_users

                    LEFT JOIN wp_usermeta
                    ON wp_users.ID = wp_usermeta.user_id

                    GROUP BY wp_users.user_login"

Open in new window

0
Comment
Question by:phillystyle123
2 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 500 total points
Comment Utility
Add after the group by

to order by :
last_name
ORDER BY 3


user_login
ORDER BY 1

first_name
ORDER BY 2
0
 

Author Closing Comment

by:phillystyle123
Comment Utility
perfecto -thanks so much for the quick reply
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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

15 Experts available now in Live!

Get 1:1 Help Now