
- 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
Fetch maximum value from a column with values as string numbers like Value440, Value345, etc. in SQL
For this, you can use MAX() along with substring(). Let us first create a table −
mysql> create table DemoTable1337 -> ( -> Value varchar(50) -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1337 values('Value400'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1337 values('Value345'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1337 values('Value567'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1337 values('Value489'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1337;
This will produce the following output −
+----------+ | Value | +----------+ | Value400 | | Value345 | | Value567 | | Value489 | +----------+ 4 rows in set (0.00 sec)
Following is the query to find maximum in value in MySQL when column is varchar −
mysql> select max(cast(substring(Value, 6) as decimal(10,2))) as MaximumValue from DemoTable1337;
This will produce the following output −
+--------------+ | MaximumValue | +--------------+ | 567.00 | +--------------+ 1 row in set (0.04 sec)
- Related Articles
- Two ways to fetch maximum value from a MySQL column with numbers
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Fetch the maximum value from a MySQL column?
- MySQL query to fetch the maximum corresponding value from duplicate column values
- MySQL query to remove string from a column with values EMP1, EMP2, EMP3, etc.
- Fetch maximum value from multiple columns with null and non-null values?
- Order by numeric value from string records separated by numbers like CSE 15, CSE 11, etc.?
- MySQL query to update all the values in a column with numeric incremental values like John1, John2, John3, etc.
- MySQL query to fetch records with arrangement in the form of numbers and letter like 99S, 50K, etc.?
- PHP fetch a specific value that begins with a given number from a string with letters and numbers?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- Finding the minimum and maximum value from a string with numbers separated by hyphen in MySQL?
- JavaScript - Find keys for the matched values as like query in SQL
- How to display highest value from a string with numbers set as varchar in MySQL?

Advertisements