C
C
CapitanFreeloader2016-10-11 11:37:28
MySQL
CapitanFreeloader, 2016-10-11 11:37:28

How to add sorting by cell value in a column in a select query?

There is a request like

SELECT `*перечень столбцов*` FROM `table` WHERE coll='чето там' ORDER BY RAND() limit 1

There was a need to add another sort. It is necessary that the lines in which the value of the column falls are not displayed like:
SELECT `*перечень столбцов*` FROM `table` WHERE coll='чето там' ORDER BY RAND() limit 1 *не выводить где col='asd' and col='asss'*

Unloading everything in php and doing sorting there is not an option, since there are already more than 1k rows.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2016-10-11
@CapitanFreeloader

1. For order by rand () you need to kill.
Google, the question "how to choose random values" was not discussed only by the lazy, on Habré articles the sea.
2. Just 1k lines can be perfectly sorted in php, the nuances begin when there are more lines by 1-2 orders of magnitude.
3.

WHERE coll='чето там' and not (coll = 'asd' or coll like 'asss%' )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question