
- 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
Get row data for the lowest and highest values in a MySQL column
For the lowest values in a MySQL column, use the MIN() method and for highest, use the MAX() method. Let us first create a table −
mysql> create table DemoTable ( CustomerName varchar(20), ProductAmount int ) ; Query OK, 0 rows affected (1.03 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris',3599); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David',7843); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Mike',97474); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Bob',65884); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+---------------+ | CustomerName | ProductAmount | +--------------+---------------+ | Chris | 3599 | | David | 7843 | | Mike | 97474 | | Bob | 65884 | +--------------+---------------+ 4 rows in set (0.00 sec)
Following is the query to get the lowest and highest values using MAX() and MIN() −
mysql> select *from DemoTable where ProductAmount=(select max(ProductAmount) from DemoTable) or ProductAmount=(select min(ProductAmount) from DemoTable);
This will produce the following output −
+--------------+---------------+ | CustomerName | ProductAmount | +--------------+---------------+ | Chris | 3599 | | Mike | 97474 | +--------------+---------------+ 2 rows in set (0.00 sec)
- Related Articles
- Pull row with lowest number in a MySQL column?
- MySQL query to get first two highest column values from a table?
- Java Program to get the lowest and highest value in TreeSet
- A single MySQL query to find the highest and lowest among two tables?
- MySQL query to get the character length for all the values in a column?
- MySQL order by from highest to lowest value?
- MySQL query to select the nth highest value in a column by skipping values
- Get multiple count in a single MySQL query for specific column values
- Get the highest score value from a single column and the greatest from two columns in MySQL
- Highest and lowest in an array JavaScript
- Write a program in Python to find the lowest value in a given DataFrame and store the lowest value in a new row and column
- How to find the column number of minimum values in each row for a data frame in R?
- MySQL query to group concat and place data into a single row on the basis of 1 values in corresponding column?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- Display all the column values in a single row separated by comma in MySQL?

Advertisements