- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to get the max value with numeric values in varchar field?
To get the max value, use the max() function. Let us create a table first −
mysql> create table findMaxValueInVarcharField -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value varchar(200) -> ); Query OK, 0 rows affected (1.09 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into findMaxValueInVarcharField(Value) values('200'); Query OK, 1 row affected (0.14 sec) mysql> insert into findMaxValueInVarcharField(Value) values('1000'); Query OK, 1 row affected (0.25 sec) mysql> insert into findMaxValueInVarcharField(Value) values('899474'); Query OK, 1 row affected (0.18 sec) mysql> insert into findMaxValueInVarcharField(Value) values('39474'); Query OK, 1 row affected (0.15 sec) mysql> insert into findMaxValueInVarcharField(Value) values('4958'); Query OK, 1 row affected (0.12 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from findMaxValueInVarcharField;
This will produce the following output −
+----+--------+ | Id | Value | +----+--------+ | 1 | 200 | | 2 | 1000 | | 3 | 899474 | | 4 | 39474 | | 5 | 4958 | +----+--------+ 5 rows in set (0.00 sec)
Following is the query to get the maximum from numeric values in a varchar field −
mysql> select max(cast(Value as unsigned) ) AS MaximumValueFromVarcharField from findMaxValueInVarcharField;
This will produce the following output −
+------------------------------+ | MaximumValueFromVarcharField | +------------------------------+ | 899474 | +------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to get max id from varchar type and the values in numeric?
- How to select only non - numeric values from varchar column in MySQL?
- Getting the maximum value from a varchar field in MySQL
- MySQL query to group rows by the numeric characters in a string field?
- How to get the max of two values MySQL?
- What is the MySQL VARCHAR max size?
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- MySQL query to update all the values in a column with numeric incremental values like John1, John2, John3, etc.
- Searching for an integer value in a varchar field in MySQL?
- MySQL query to get a field value that does not contain empty spaces?
- Select query to display duplicate values with max date
- Get MAX and MIN values along with their row id in MySQL?
- Sorting varchar field numerically in MySQL?
- MySQL query to count comma’s from field value?
- Delete last value and fix two new values (VARCHAR Numbers) in MySQL declared as VARCHAR?

Advertisements