1

I have a mysql table like this

Brand     Count
TOYOTA     20
HONDA      50
BMW        5
PORSCHE    10
HYUNDAI    10
MAZDA      10

I want to sort the table based on the COUNT column in Descending and in-case of tie I want to order the BRAND column to PORSCHE, BMW, HONDA, TOYOTA, MAZDA, HYUNDAI so the result will be like below:

Brand     Count
HONDA      50
TOYOTA     20
PORSCHE    10
BMW        10
HYUNDAI    10
MAZDA      5 
user3913971
  • 13
  • 1
  • 4

1 Answers1

1

use FIELD() for custom ordering

ORDER BY `Count` DESC, 
         FIELD(BRAND, 'PORSCHE', 'BMW', 'HONDA', 'TOYOTA', 'MAZDA', 'HYUNDAI')
John Woo
  • 258,903
  • 69
  • 498
  • 492