DeLe
DeLe

Reputation: 2480

MySQL - Order specific field values in multi column

I have table like

+-----------+------------+------+------+------+
| id        | name       | col1 |col2  | col3 |
+-----------+------------+------+------+------+

I want order my table with two column like (col1, col2) in (v1,v1),(v2,v2)... and some other order.

In MySQL has ORDER BY FIELD(col1, 'v1', 'v2', 'v3') DESC, other columns ASC; but how using it in multi column like my example thanks.

Upvotes: 0

Views: 21

Answers (1)

Barmar
Barmar

Reputation: 780724

You can concatenate the strings.

ORDER BY FIELD(CONCAT(col1, ',', col2), 'v1,v1', 'v2,v2', ...)

Upvotes: 1

Related Questions