ORDER BY multiple factors?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

ORDER BY multiple factors?

Post by Sindarin »

I am trying to order results by 2 values, article_importance and article_publish_date,

Using,
ORDER BY article_importance ASC AND article_publish_date ASC
generates a syntax error. Any help?
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: ORDER BY multiple factors?

Post by mintedjo »

I think its a comma instead of AND

Code: Select all

ORDER BY article_importance ASC, article_publish_date ASC
If thats not right then try it without a comma

Code: Select all

ORDER BY article_importance ASC article_publish_date ASC
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: ORDER BY multiple factors?

Post by pbs »

Also try

ORDER BY article_importance, article_publish_date ASC
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: ORDER BY multiple factors?

Post by mintedjo »

pbs wrote:

Code: Select all

ORDER BY article_importance, article_publish_date ASC
Doesn't account for the situation where you need to order one thing asc and another desc :-(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: ORDER BY multiple factors?

Post by Chris Corbyn »

mintedjo wrote:
pbs wrote:

Code: Select all

ORDER BY article_importance, article_publish_date ASC
Doesn't account for the situation where you need to order one thing asc and another desc :-(

Code: Select all

ORDER BY article_importance ASC, article_publish_date DESC
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: ORDER BY multiple factors?

Post by mintedjo »

Chris Corbyn wrote:
mintedjo wrote:
pbs wrote:

Code: Select all

ORDER BY article_importance, article_publish_date ASC
Doesn't account for the situation where you need to order one thing asc and another desc :-(

Code: Select all

ORDER BY article_importance ASC, article_publish_date DESC
I already posted that exact code above, only using 2 ascendings because... well thats what the question was about :-P
Post Reply