Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Suppose User is looking a website from kolkata and If user search the content then data will appear by latest datetime wise and by current city kolkata(Current Place).

What I have tried:

I have tried select query with multiple order by clause

select * from TABLE order by date desc, city desc
Posted
Updated 1-Apr-16 22:39pm
v3
Comments
Karthik_Mahalingam 2-Apr-16 3:43am    
you mean to say, display kolkata data first followed by other city data ?
itsathere 2-Apr-16 4:01am    
Yes.
Karthik_Mahalingam 2-Apr-16 4:08am    
ok. you will be getting the kolkata value from the geo location rite?
itsathere 2-Apr-16 4:12am    
No, from database. I think it does't matter.

1 solution

try this

SQL
select * , 'key' = 'a' from city where CityName = 'kolkata'   
union all
select * ,'key' = 'b' from city where CityName <> 'kolkata'  order by 'key', DateColumn desc 
 
Share this answer
 
v2
Comments
itsathere 2-Apr-16 9:51am    
what is 'key'='a'
Karthik_Mahalingam 2-Apr-16 9:54am    
it is for reference to do the sorting.. you can ignore this column while selecting data from the query.
itsathere 2-Apr-16 10:03am    
Explain please.
Karthik_Mahalingam 2-Apr-16 10:07am    
see, if we do order by DateColumn desc
it wont consider the city, rather it will fetch all the data with date in descending order, to avoid that i have introduced a new column key to separate the two results.
run and see with and without key, you will find the difference..
itsathere 2-Apr-16 10:09am    
Yes, Its working.Thanks for explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900