- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
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)
Advertisements