Reputation: 8091
so here's the problem
I have 3 types for a hotel
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
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
Reputation: 14664
I will use group by on hotel type and sort by desc in your case. Try writing the query.
Upvotes: 0