Little advance mysql order by query -


i use following working mysql query:

select *  tabs   order      featured desc,      case when  city='$city' 0 else 1 end,      hits desc 

it returns data order featured first , rows has city values , hits.

the database table 'tabs' has following order

  1. id(int)
  2. city(text)
  3. tabname(text)
  4. hits(int)
  5. featured (int)

how can data order featured in city first other data city order hits

for example

if live in rome , want data return in order. tabs comes first has city='rome' , featured='1', , other tabs rome (same city city='rome'), , hits desc.

i have tried following failed :

select * tabs   order      featured desc,      case when  featured='1' , city='$city' 0 else 1 end,      case when city='$city' 0 else 1 end,      hits desc 

please have try one:

select * tabs   order featured desc,  case when featured='1' , city='$city' 0      when featured='0' , city='$city' 1 else 2 end,  hits desc 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -