
- 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
MySQL query to display ASC order in number column?
You can achieve this with the help of CAST() function. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score int ); Query OK, 0 rows affected (0.72 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Score) values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Score) values(100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Score) values(11); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Score) values(97); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Score) values(89); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-------+ | Id | Score | +----+-------+ | 1 | 10 | | 2 | 100 | | 3 | 11 | | 4 | 97 | | 5 | 78 | | 6 | 89 | +----+-------+ 6 rows in set (0.00 sec)
Following is the query to set ASC order in number column −
mysql> select *from DemoTable order by cast(Score AS SIGNED INTEGER) ASC;
This will produce the following output −
+----+-------+ | Id | Score | +----+-------+ | 1 | 10 | | 3 | 11 | | 5 | 78 | | 6 | 89 | | 4 | 97 | | 2 | 100 | +----+-------+ 6 rows in set (0.00 sec)
- Related Articles
- MySQL ORDER BY ASC and display NULLs at the bottom?
- Order By date ASC in MySQL?
- Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query
- MySQL query to display only the column values with corresponding column having whitespace
- Implement MySQL ORDER BY without using ASC or DESC?
- MySQL query to get the count of values and display the count in a new column ordered in descending order\n
- Displaying only a list of records in ASC order with MySQL
- MySQL Order by a specific column x and display remaining values in ascending order
- MySQL query to display the first alphabet from strings in a separate column
- MySQL query to group by column and display the sum of similar values in another column
- MySQL query to order and display difference between dates from the current date
- MySQL query to group by names and display the count in a new column
- MySQL query to display the column and its values using OR in WHERE statement
- MySQL query to count the number of 0s and 1s from a table column and display them in two columns?
- MySQL query to count number of duplicate values in a table column

Advertisements