MySQL query ignoring "ORDER BY" clause?

Thread Solved

Join Date: Jun 2009
Posts: 15
Reputation: jay.barnes is an unknown quantity at this point 
Solved Threads: 0
jay.barnes jay.barnes is offline Offline
Newbie Poster

MySQL query ignoring "ORDER BY" clause?

 
0
  #1
Aug 19th, 2009
Good morning/afternoon/evening!

I'm trying to run a MySQL query, but it seems to be ignoring the "ORDER BY" clause, most likely, I'm believing, because I'm using the "IN" keyword in my query (several times, as a matter of fact, along with a "LIKE"). Is there a way I can structure my query, so that it will use the "ORDER BY" clause? I've included an example of the query below:

  1. SELECT * FROM Ships, Accounts WHERE Available_Loads.Action != 'D'
  2. AND Ships.Username = Accounts.Username
  3. AND Ships.Username != 'demo'
  4. AND Ships.Status != 'inactive'
  5. AND Ships.PU_Date >= CURRENT_DATE()
  6. AND Ships.Shipment_Type LIKE '%'
  7. AND Ships.Required_Equipment IN ('AC', 'DD')
  8. AND Ships.Origin_Country IN ('USA')
  9. AND Ships.Origin_State IN ('TX')
  10. AND Ships.Origin_City IN ('ALLEN', 'ARGYLE', 'ARLINGTON', 'AUBREY', 'BEDFORD', 'CARROLLTON', 'CEDAR HILL', 'CELINA', 'COLLEYVILLE', 'COPPELL', 'DALLAS', 'DENTON', 'DESOTO', 'DUNCANVILLE', 'EULESS', 'FLOWER MOUND', 'FORT WORTH', 'FRISCO', 'GARLAND', 'GRAND PRAIRIE', 'GRAPEVINE', 'HURST', 'IRVING', 'KELLER', 'LAKE DALLAS', 'LAVON', 'LEWISVILLE', 'LITTLE ELM', 'MCKINNEY', 'MELISSA', 'MESQUITE', 'NORTH RICHLAND HILLS', 'PLANO', 'PRINCETON', 'PROSPER', 'RICHARDSON', 'ROANOKE', 'ROWLETT', 'SOUTHLAKE', 'SUNNYVALE', 'THE COLONY', 'WYLIE')
  11. AND Ships.Dest_Country IN ('USA')
  12. AND Ships.Dest_State IN ('LA') ORDER BY 'PU_Date ASC'

Thanks for any suggestions you can provide!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 55
Reputation: wilch is an unknown quantity at this point 
Solved Threads: 9
wilch wilch is offline Offline
Junior Poster in Training

Re: MySQL query ignoring "ORDER BY" clause?

 
0
  #2
Aug 19th, 2009
  1. AND Ships.Dest_State IN ('LA') ORDER BY 'PU_Date ASC'
In this last line, you have i think mistakenly put the keyword ASC as part of the column name. Try removing the ASC from the quotes !
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,387
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 168
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: MySQL query ignoring "ORDER BY" clause?

 
1
  #3
Aug 19th, 2009
Originally Posted by wilch View Post
  1. AND Ships.Dest_State IN ('LA') ORDER BY 'PU_Date ASC'
Try removing the ASC from the quotes !
good catch, stared at it and didnt see
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 15
Reputation: jay.barnes is an unknown quantity at this point 
Solved Threads: 0
jay.barnes jay.barnes is offline Offline
Newbie Poster

Re: MySQL query ignoring "ORDER BY" clause?

 
0
  #4
Aug 19th, 2009
Originally Posted by almostbob View Post
good catch, stared at it and didnt see
I'll give it a shot, but what if I want to specify the ORDER BY clause to be ascending or descending?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 55
Reputation: wilch is an unknown quantity at this point 
Solved Threads: 9
wilch wilch is offline Offline
Junior Poster in Training

Re: MySQL query ignoring "ORDER BY" clause?

 
0
  #5
Aug 19th, 2009
  1. ...AND Ships.Dest_State IN ('LA') ORDER BY 'PU_Date' ASC
The ASC is out of the quotes, what's in the quotes is the column name !

Don't forget to mark as solved, if solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 15
Reputation: jay.barnes is an unknown quantity at this point 
Solved Threads: 0
jay.barnes jay.barnes is offline Offline
Newbie Poster

Re: MySQL query ignoring "ORDER BY" clause?

 
0
  #6
Aug 19th, 2009
Ah, got it, thanks!

I ended up having to remove the single quotes from the "ORDER BY" clause entirely to get it to work.

Thank you for the guidance and advice, guys! I appreciate it!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 55
Reputation: wilch is an unknown quantity at this point 
Solved Threads: 9
wilch wilch is offline Offline
Junior Poster in Training

Re: MySQL query ignoring "ORDER BY" clause?

 
1
  #7
Aug 19th, 2009
Welcome brother !
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC