Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-22-2004, 05:53 AM   #1 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Using ORDER BY in a select statement

I want to pull several rows out of a database ordered first by city name, then by price (it's for real-estate listings). I know how to order by one field, like this:
Code:
$query = "SELECT * FROM listings WHERE 1 ORDER BY price DESC";
But how would I order it first by the city, then by the prices (from high to low) within that city so that they come out in an order like this:

city1, high-price
city1, med-price
city1, low-price
city2, high-price
city2, low-price
city3, high-price
...and so on.

Thanks for any tips.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 08-22-2004, 07:45 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
try this:
Code:
select * from listings where 1 order by city asc, price desc
i haven't tested it, but i'm pretty sure that query will work with mysql.
__________________
Mike

Last edited by sde; 08-22-2004 at 02:28 PM.
sde is offline   Reply With Quote
Old 08-22-2004, 01:36 PM   #3 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Code:
select * from listings where 1 order by price city asc, price desc
Was that first 'price' meant literally?
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 08-22-2004, 02:28 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
no, sorry. i fixed it.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
someone please help kickerman97 Java 3 10-19-2004 03:19 PM
Nested subquery within the Select clause jsze Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 6 10-12-2004 10:23 AM
Search -That Can Match Out Of Order Items JBurke All Other Coding Languages 11 09-25-2003 02:09 PM
mixing AND & OR in an sql statement sde PHP 1 03-15-2003 01:01 AM
dynamic select menues sde HTML, XML, Javascript, AJAX 5 02-15-2003 09:05 AM


All times are GMT -8. The time now is 11:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting