
- 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
Return maximum value from records in MySQL
Let us first create a table −
mysql> create table DemoTable1449 -> ( -> PlayerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> PlayerScore int -> ); Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1449(PlayerScore) values(1040); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1449(PlayerScore) values(1450); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1449(PlayerScore) values(1890); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable1449(PlayerScore) values(1650); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1449;
This will produce the following output −
+----------+-------------+ | PlayerId | PlayerScore | +----------+-------------+ | 1 | 1040 | | 2 | 1450 | | 3 | 1890 | | 4 | 1650 | +----------+-------------+ 4 rows in set (0.00 sec)
Following is the query to return maximum value from records −
mysql> select PlayerId,PlayerScore from DemoTable1449 -> where PlayerScore=( select max(PlayerScore) PlayerScore from DemoTable1449);
This will produce the following output −
+----------+-------------+ | PlayerId | PlayerScore | +----------+-------------+ | 3 | 1890 | +----------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to return 5 random records from last 20 records?
- Get maximum age from records with similar student names in MySQL
- Get three records having higher value from MySQL
- Find maximum value from a VARCHAR column in MySQL
- Get MySQL maximum value from 3 different columns?
- Fetch the maximum value from a MySQL column?
- Getting the maximum value from a varchar field in MySQL
- How to select return value from MySQL prepared statement?
- MongoDB query to get minimum and maximum value from documents including some duplicate records
- MySQL stored procedure return value?
- Insert records from multiple tables in MySQL
- How to get the maximum value from strings with integers in MySQL?
- Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL
- How to delete a single value from a MySQL table with duplicate records?
- MySQL TINYINT type to return 1 or IS NULL records

Advertisements