
- 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
Find maximum value from a VARCHAR column in MySQL
To find maximum value, use MAX() along with CAST(), since the values are of VARCHAR type. Let us first create a table −
mysql> create table DemoTable2030 -> ( -> Value varchar(20) -> ); Query OK, 0 rows affected (0.44 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2030 values('8'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2030 values('1'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2030 values('10001'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2030 values('901'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement &miuns;
mysql> select *from DemoTable2030
This will produce the following output −
+-------+ | Value | +-------+ | 8 | | 1 | | 10001 | | 901 | +-------+ 4 rows in set (0.00 sec)
Following is the query to find maximum value from a VARCHAR column −
mysql> select max(cast(Value as unsigned)) from DemoTable2030;
This will produce the following output −
+------------------------------+ | max(cast(Value as unsigned)) | +------------------------------+ | 10001 | +------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Getting the maximum value from a varchar field in MySQL
- Get the minimum and maximum value from a VARCHAR column and display the result in separate MySQL columns?
- How to get a value more than a particular value from varchar column in MySQL?
- Fetch the maximum value from a MySQL column?
- Find the Maximum Value in a Column in MySQL
- What is the maximum length of MySQL VARCHAR column?
- How to alter a MySQL Column from varchar(30) to varchar(100)?
- Alter a table column from VARCHAR to NULL in MySQL
- Get maximum date from a list of varchar dates in MySQL
- Find date record after a particular date from a column with VARCHAR type in MySQL
- Two ways to fetch maximum value from a MySQL column with numbers
- MySQL query to fetch the maximum corresponding value from duplicate column values
- How to select only non - numeric values from varchar column in MySQL?
- How to select the maximum value of a column in MySQL?
- Getting maximum from a column value and set it for all other values in the same column with MySQL?

Advertisements