943,879 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 833
  • MySQL RSS
Aug 19th, 2009
0

MySQL query ignoring "ORDER BY" clause?

Expand Post »
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:

MySQL Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 14
Solved Threads: 0
Light Poster
jay.barnes is offline Offline
45 posts
since Jun 2009
Aug 19th, 2009
0

Re: MySQL query ignoring "ORDER BY" clause?

MySQL Syntax (Toggle Plain Text)
  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 !
Reputation Points: 21
Solved Threads: 15
Junior Poster in Training
wilch is offline Offline
76 posts
since Aug 2007
Aug 19th, 2009
1

Re: MySQL query ignoring "ORDER BY" clause?

Click to Expand / Collapse  Quote originally posted by wilch ...
MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Aug 19th, 2009
0

Re: MySQL query ignoring "ORDER BY" clause?

Click to Expand / Collapse  Quote originally posted by almostbob ...
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?
Reputation Points: 14
Solved Threads: 0
Light Poster
jay.barnes is offline Offline
45 posts
since Jun 2009
Aug 19th, 2009
0

Re: MySQL query ignoring "ORDER BY" clause?

MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 21
Solved Threads: 15
Junior Poster in Training
wilch is offline Offline
76 posts
since Aug 2007
Aug 19th, 2009
0

Re: MySQL query ignoring "ORDER BY" clause?

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!
Reputation Points: 14
Solved Threads: 0
Light Poster
jay.barnes is offline Offline
45 posts
since Jun 2009
Aug 19th, 2009
1

Re: MySQL query ignoring "ORDER BY" clause?

Welcome brother !
Reputation Points: 21
Solved Threads: 15
Junior Poster in Training
wilch is offline Offline
76 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Empty result set
Next Thread in MySQL Forum Timeline: how to query the first 4 letters and the last 4 letters of field





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC