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:

SELECT * FROM Ships, Accounts WHERE Available_Loads.Action != 'D'
AND Ships.Username = Accounts.Username
AND Ships.Username != 'demo'
AND Ships.Status != 'inactive'
AND Ships.PU_Date >= CURRENT_DATE()
AND Ships.Shipment_Type LIKE '%'
AND Ships.Required_Equipment IN ('AC', 'DD')
AND Ships.Origin_Country IN ('USA')
AND Ships.Origin_State IN ('TX')
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')
AND Ships.Dest_Country IN ('USA')
AND Ships.Dest_State IN ('LA') ORDER BY 'PU_Date ASC'

Thanks for any suggestions you can provide!

Recommended Answers

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 !

Jump to Post
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

Jump to Post

All 6 Replies

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 !

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

commented: Thanks for the help with my MySQL query issue! +1

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?

...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 ;)

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!

Welcome brother !

commented: Thanks for the help with my MySQL query issue! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.