
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Sort items of an ArrayList with Collections.reverseOrder() in Java
- Sort id and reverse the items with MongoDB
- Sort items in a Java TreeSet
- Distinct number of specific items in list with MySQL
- Replacing dots with dashes in a string using JavaScript
- Call aggregate function in sort order with MySQL
- Sort in a string mixed with numbers in MySQL?
- Count items in a MySQL table with type ENUM involved?
- MySQL LIKE command doesn't work with strings containing dots to display records beginning with a specific number
- MongoDB query to find records with keys containing dots?
- MySQL query to add dots if string has more than 10 words?
- Python – Sort List items on basis of their Digits
- How can we sort the items of a JComboBox in Java?
- Count and sort rows with a single MySQL query
- How to sort by value with MySQL ORDER BY?

Advertisements