Re: ORDER BY Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <20030905122903.54348.qmail@pb1.pair.com>, shaun@mania.plus.com 
says...
> Hi,
> 
> I have a table in my database called Users. This table has (among others)
> two columns called Location and Name. Location will be either 1, 2, 3, or 4.
> How can I produce a query that groups the result into Location and then for
> each Location order the User by Name?
> 
> Thanks for your help.

You'll need to mix a bit of php with your sql to get the desired result.

SELECT * FROM Users WHERE whatever ORDER BY Location, Name

Then when you display the results, initialise a variable to keep track of 
the last value of Location. If it differs from the current value, display 
the location. This way you end up with something like:

Location: 1
Bill
Fred
George
Location: 2
John
Agatha
Mercedes

etc etc

-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux