Current location: Hot Scripts Forums » Programming Languages » PHP » Getting results with ORDER BY and GROUP BY?


Getting results with ORDER BY and GROUP BY?

Reply
  #1 (permalink)  
Old 11-01-05, 07:57 PM
Tim Mousel Tim Mousel is offline
Wannabe Coder
 
Join Date: Jan 2005
Posts: 157
Thanks: 0
Thanked 0 Times in 0 Posts
Question Getting results with ORDER BY and GROUP BY?

Hi,

PHP Code:

$query "select q.item_id_q, q.q_id, q.username,

 review_items.item_name, q.q_date, review_items.item_id, q.priority 
FROM review_items, q WHERE review_items.inventory != 0 AND q.item_id_q = review_items.item_id 
GROUP BY q.q_date 
ORDER BY q.q_date, q.username, q.priority"

The query above does everything I want it to but it does NOT order the output by priority.

How can I rewrite this to make it group by the date and then within those groups, order by date (oldest first), username and priority (numerical field) from low to high.

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-01-05, 11:25 PM
nugensoftware's Avatar
nugensoftware nugensoftware is offline
Newbie Coder
 
Join Date: Oct 2005
Location: United States
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$query "select q.item_id_q, q.q_id, q.username,

 review_items.item_name, q.q_date, review_items.item_id, q.priority 
FROM review_items, q WHERE review_items.inventory != 0 AND q.item_id_q = review_items.item_id 
GROUP BY q.q_date 
ORDER BY q.q_date DESC, q.username DESC, q.priority ASC"



add DESC, ASC at the end of the variables you are wanting to order by if you use more than 1 field.
__________________
Nugen Software Inc.
Lead Developer
www.nugensoftware.com

PHP HELP | MySQL HELP | xmlSYNC
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-01-05, 11:50 PM
Tim Mousel Tim Mousel is offline
Wannabe Coder
 
Join Date: Jan 2005
Posts: 157
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Unfortunately, that didn't sort the priority column.


Any other ideas?

Thanks,

Tim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-02-05, 12:39 AM
nugensoftware's Avatar
nugensoftware nugensoftware is offline
Newbie Coder
 
Join Date: Oct 2005
Location: United States
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Tim Mousel
Hi,

Unfortunately, that didn't sort the priority column.


Any other ideas?

Thanks,

Tim
The only other help I can give you would be the ORDER_BY examples in the MySQL manaual. I've ran into this same issue in the past myself. I can't remember how I sorted it out for the life of me.

http://dev.mysql.com/doc/refman/4.1/...imization.html

I just checked one of my SQL statements and I'm basicly using the above example and its working. Remember DESC is descending and ASC is ascending.
__________________
Nugen Software Inc.
Lead Developer
www.nugensoftware.com

PHP HELP | MySQL HELP | xmlSYNC
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Group By... djavet PHP 1 05-07-04 06:17 AM


All times are GMT -5. The time now is 01:11 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.