Sorry about my mistake, I should provide the real sample for the question, my ID included characters inside:
sample code:
select ID from student order by ID
Expected output from mine but system output
------------------------- -----------------
JAD.1.99.9 JAD.1.99.10
JAD.1.99.10 JAD.1.99.9
and this ID
is of nvarchar
type.
It will order the results by the first column, and then, if there are some rows with the same value in the first column it will order them by the second column.
'LPAD(lower(column_name))' is used to sort the varchar field numerically in MySQL. Let us see an example. Firstly, we will create a table. The CREATE command is used to create a table.
The order statement generates a 'virtual field' that contains NULL or 0 based on the case condition. The ORDER BY is applied based on that virtual field. The zero value in the order by precedes the NULL value. That's all, it's a way to set NULLs of the field1 at the end of the order list.
In short, no, they do not matter as the optimizer will determine the best means for fetching the data.
Yesterday there was a similar question where i have learned that you can use hierarchyid
for version sorting(if you use at least SQL-Server 2008):
SELECT id
FROM student
ORDER BY Cast('/' + Replace(id, '.', '/') + '/' AS HIERARCHYID)
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With