Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query ordering

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
AU
Given the query:

select *
from clients
WHERE (post=4555) OR (post=4074) OR (post=4064)

Is there any way to order this by what I have specified in the 'OR' clause? i.e. I want this to return:

xxx POST
... 4555
... 4074
... 4064

I am doing a proximity based search (calculating distances between postcodes using latitudes and longitudes) using PHP and want to order this by proximity.

Given that my query can return up 1000 postcodes, I have three options here:

1. Do a separate query for each post code (* yuck *)
2. Do a table sort in HTML page on the proximity column after outputting my results (* better *)
3. Somehow get MySQL to output the results in the order of the fields in the 'OR' clause. (* best *)

Thanks.


------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
select ...
from clients
where post in (4555,4074,4064)
order by field(post,4555,4074,4064)



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top