A
A
Anatoly2017-10-21 12:21:33
MySQL
Anatoly, 2017-10-21 12:21:33

How to organize random sorting by a specific field?

Good afternoon!
I asked myself this question:
Is it possible to organize sorting by one field with additional random sorting by the second field?
For example:
There is a table like this

---------------------------------
| id | title | type| created_at |
---------------------------------
| 1 | A      |  2  | 21.10.2017 |
| 2 | B      |  2  | 22.10.2017 |
| 3 | C      |  2  | 23.10.2017 |
| 4 | D      |  3  | 24.10.2017 |
| 5 | E      |  4  | 25.10.2017 |
---------------------------------

To get something like this:
------------------------------------
| id | title | type ↓ | created_at |
------------------------------------
| 2 | B      |  2     | 22.10.2017 |
| 1 | A      |  2     | 21.10.2017 |
| 3 | C      |  2     | 23.10.2017 |
| 4 | D      |  3     | 24.10.2017 |
| 5 | E      |  4     | 25.10.2017 |
------------------------------------

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Interreto, 2017-10-21
@les-anatoliy

order by <column name or number> [asc|desc], rand()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question