- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sort items in MySQL with dots?
Let us first create a table −
mysql> create table DemoTable -> ( -> Value varchar(20) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('20'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('10.5'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('11'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('10'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('20.5'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 20 | | 10.5 | | 11 | | 10 | | 20.5 | +-------+ 5 rows in set (0.00 sec)
Here is the query to sort items in MySQL with dots −
mysql> select *from DemoTable -> order by CAST(Value AS DECIMAL) ASC;
This will produce the following output −
+-------+ | Value | +-------+ | 10 | | 10.5 | | 11 | | 20 | | 20.5 | +-------+ 5 rows in set (0.00 sec)
Advertisements