yretuta
yretuta

Reputation: 8091

sorting with 3 categories

so here's the problem

I have 3 types for a hotel

  1. premium
  2. featured
  3. basic

I am trying to display a list of hotels and sort them so that featured hotels are the first shown

what mysql query would accomplish this?

EDIT here's the table, with some fields stripped

ID | hotel_name | type
=======================
1 | Aria Hotel | basic

Upvotes: 2

Views: 91

Answers (2)

YOU
YOU

Reputation: 123841

ORDER BY FIELD(type, 'featured', 'premium', 'basic')

You could rearrange 'featured', 'premium', 'basic' upto your needs, and may also put DESC there too

For example

ORDER BY FIELD(type, 'featured', 'premium', 'basic') DESC

or to arrange the rest as normal sorting order.

ORDER BY FIELD(type, 'featured', 'premium', 'basic') DESC, type;

Upvotes: 1

Boolean
Boolean

Reputation: 14664

I will use group by on hotel type and sort by desc in your case. Try writing the query.

Upvotes: 0

Related Questions