ORDER by ??

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
ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

ORDER by ??

Post by ssand »

I have a simple ORDER by:

Code: Select all

$sql = "SELECT * FROM classifieds order by run_date desc";
Is it possible to have it then sort by another column? So, the results are by run_date then ad_name (where ad_name is not desc)??

Steve
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried,

Code: Select all

$sql = "SELECT * FROM classifieds ORDER BY run_date DESC, ad_name";
Mac
ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

Post by ssand »

thanks :D
User avatar
Toneboy
Forum Contributor
Posts: 102
Joined: Wed Jul 31, 2002 5:59 am
Location: Law, Scotland.
Contact:

Post by Toneboy »

Glad I did a search on here before posting a new topic!

Basically I have a small link system in place, and I would like to order it by the number of hits a link has had, but then if two links have had the same number of hits could you order those in ascending alphabetical order.

From the above example I'd imagine a line would look a bit like this:

"SELECT * FROM links ORDER BY hits DESC, name ASC"

Can anyone confirm this one way or another?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The syntax for that looks right so all you need to do is try it out on your table content.

Mac
Post Reply