0

I want to order the results of a mysql query

1) to show first entrys wich match a given condition and order them randomly

2) and then show the rest of the results ordered by date desc

i tryed already this:

Select * from post inner join user on post.user_id = user.id order by user.type = "top" desc, created desc;

many thanks

Mik
  • 1,705
  • 1
  • 14
  • 26
  • You need to write 2 selects and use union between them – Aivar May 10 '13 at 09:52
  • actually my goal was to do it without union, as this query is part of a complex filter action, maybe you have an alternative, but many thanks for the hint – Mik May 10 '13 at 09:56

1 Answers1

1

Use a case statement

select * from post 
inner join user on post.user_id = user.id 
order by case when user.type = 'top' 
              then 1 
              else 2 
         end asc, 
         created desc;
juergen d
  • 201,996
  • 37
  • 293
  • 362