Possible Duplicate:
Database query to search using address
I am developing a search functionality to search for dealers by their address (i.e by postcode(zip) or by name or by city) for my project. User will be provided with only one html input field to enter the search term (users can enter only one search term at a time i.e either zip code or name or city (combinations are not allowed)).
The conditions to develop a query are as below
- when user search by zip code, matched results should be displayed in descending order
- when user search by name matched results should be display alphabetically same as city name
Some times there is a possibility that name can also contains zip code in that case results should be shorted by zip code.
I tried like this
select city, postcode, name
from dealers
where name ='xyz'
OR postcode ='xyz'
OR city='XYZ'
ORDER BY postcode desc
But Ii want ORDER BY for every condition. for example ‘xyz’ matches to the firstname I want to sort the result in ascending order.
How can i do that? Any suggestions will be greatly appriciated
Try this: