
- 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
What is the purpose of ORDER BY columnname*1 in MySQL?
MySQL will implicitly convert the column into a number. Following is the syntax −
select * from yourTableName order by yourColumnName*1;
Let us first create a −
mysql> create table DemoTable1441 -> ( -> Id varchar(30) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1441 values('301'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1441 values('23'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1441 values('345'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable1441 values('10'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1441 values('38'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select −
mysql> select * from DemoTable1441;
This will produce the following output −
+------+ | Id | +------+ | 301 | | 23 | | 345 | | 10 | | 38 | +------+ 5 rows in set (0.00 sec)
Following is the query to use order by columnname*1 −
mysql> select * from DemoTable1441 -> order by id*1;
This will produce the following output −
+------+ | Id | +------+ | 10 | | 23 | | 38 | | 301 | | 345 | +------+ 5 rows in set (0.00 sec)
- Related Articles
- What is the use of ORDER BY clause in MySQL?
- What is the purpose of MySQL TRIM() function?
- Difference between count(*) and count(columnName) in MySQL?
- What would happen if we run SELECT WHERE columnName = zero in MySQL?
- MySQL “order by” inside of “group by”? Is it possible?
- Order By Length of Column in MySQL
- Order by number of chars in MySQL?
- What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?
- What is the default sort order in MySQL tables?
- Is there a default ORDER BY value in MySQL?
- What is the purpose of ‘is’ operator in C#?
- What is the purpose of the Inner Engineering Program by ISHA YOGA Center?
- Order strings by length of characters IN mYsql?
- What is the purpose of interfaces in java?
- What is the purpose of VOLUME in Dockerfile?

Advertisements