skip to Main Content

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


  1. 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 not blank nither empty, but rather unknown – a string column such as char or varchar might contain an empty string – but an empty string is not equivalent to null.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search