Solved

Using Group By AND Order By in query

Posted on 2014-03-12
2
286 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

687 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