
- 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
Select minimum row value from a column with corresponding duplicate column values in MySQL
Let us first create a table −
mysql> create table DemoTable1875 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Class varchar(20), Amount int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1875(Class,Amount) values('X',750); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('X',140); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('X',450); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Y',6780); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Z',1350); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Z',2050); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1875;
This will produce the following output −
+----+-------+--------+ | Id | Class | Amount | +----+-------+--------+ | 1 | X | 750 | | 2 | X | 140 | | 3 | X | 450 | | 4 | Y | 6780 | | 5 | Z | 1350 | | 6 | Z | 2050 | +----+-------+--------+ 6 rows in set (0.00 sec)
Following is the query to select row
mysql> select Class,Min(Amount) from DemoTable1875 group by Class;
This will produce the following output −
+-------+-------------+ | Class | Min(Amount) | +-------+-------------+ | X | 140 | | Y | 6780 | | Z | 1350 | +-------+-------------+ 3 rows in set (0.00 sec)
- Related Articles
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- Add records from corresponding duplicate values in another column with MySQL
- MySQL query to fetch the maximum corresponding value from duplicate column values
- Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
- How to select the sum of the column values with higher value in reach row with MySQL?
- MySQL randomly select 2 values from column values?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Select a specific value between two column values in MySQL?
- MySQL CONCAT a specific column value with the corresponding record
- MySQL SELECT to sum a column value with previous value
- MySQL query to display only the column values with corresponding column having whitespace
- MySQL query to return the count of only NO values from corresponding column value
- How to add a column from a select query but the value from the new column will be the row count of the MySQL select query?
- Get the count of duplicate values from a single column in MySQL?
- Find and display duplicate values only once from a column in MySQL

Advertisements