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
Solved

Using Group By AND Order By in query

Posted on 2014-03-12
2
280 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
ID: 39924568
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
ID: 39924642
perfecto -thanks so much for the quick reply
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
push Book Today button to right 10 37
Split wordpress loop 35 56
IP 10.0.1.2 / 255.0.0.0 61 56
jQuery force form POST 7 46
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 …
Creating and Managing Databases with phpMyAdmin in cPanel.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

860 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