I have a query like this,
SELECT colA, colB, colC, colD FROM myTable ORDER BY colC ASC;
Here, in myTable, all the values in the column colC
are Empty/Blank/NULL. Now, how MySQL will behave in this scenario? I know the query will still execute without errors. But I am curious about how the SORTING will behave if all values of that mentioned column are Empty/Blank/NULL. On what column, the SORTING will happen on the result set?
SELECT colA, colB, colC, colD FROM myTable ORDER BY colC ASC;
2
Answers
If all the values in
colC
are the same, the rows will be returned in an arbitrary order.Please note that arbitrary isn’t necessarily random – its not likely you’ll get a different order of rows each time you run the query, however there’s no way for the database to guarantee any particular order of the rows if the column used in the
order by
clause contains the same values in all the rows returned by the query.Please note that
null
is notblank
nitherempty
, but ratherunknown
– a string column such aschar
orvarchar
might contain an empty string – but an empty string is not equivalent tonull
.The rows with empty/blank/NULL values in
colC
will likely appear together at either the beginning or the end of the sorted result set, depending on the specific implementation or version of MySQL being used.