
- 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
How to treat MySQL longtext as integer in MySQL query?
Let us first create a table −
mysql> create table DemoTable -> ( -> Value longtext -> ); Query OK, 0 rows affected (0.94 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('778437437447488487476464644433334'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('9998888485775775757577578585'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('8888874757757757757757575675656'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('988757757574646'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+-----------------------------------+ | Value | +-----------------------------------+ | 778437437447488487476464644433334 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 988757757574646 | +-----------------------------------+ 4 rows in set (0.00 sec)
Here is the query to treat MySQL longtext as integer in query −
mysql> select * from DemoTable -> order by Value+0;
This will produce the following output −
+-----------------------------------+ | Value | +-----------------------------------+ | 988757757574646 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 778437437447488487476464644433334 | +-----------------------------------+ 4 rows in set (0.03 sec)
- Related Articles
- How to treat NULL as 0 and add columns in MySQL?
- Query for implementing MySQL LIKE as MySQL IN?
- Limit length of longtext field in MySQL SELECT results?
- Treat a MySQL column field as NULL if it is blank?
- How to query soundex() in MySQL?
- In MySQL, how can we represent the time value as an integer?
- Datetime to Integer in MySQL?
- How to concat Values in MySQL Query and to handle Null values as well?
- How to get MySQL query result in same order as given by IN clause?
- How to query JSON datatype in MySQL?
- How to get MySQL random integer range?
- How to round down to nearest integer in MySQL?
- How to enable MySQL Query Log?
- MySQL query to copy IP address from varchar column to integer in the same table?
- How to get file extension of file as a result of MySQL query?

Advertisements