A
A
artmirarmi2018-02-11 06:49:08
MySQL
artmirarmi, 2018-02-11 06:49:08

How to sort by multiple fields?

There is a table with the fields id, shopID, description, active, vip.
You need to display 9 records sorted by id, but so that records with vip=1 are first, and records with shopID are also first, but after vip.
this query does not work correctly:

SELECT id, shopID, description FROM shops WHERE active=1 ORDER BY id, vip, FIELD(shopID, 3) DESC LIMIT 0, 9

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question