- 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
Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
To get minimum value from a column with corresponding duplicate ids, use GROUP BY and MIN() −
select min(yourColumnName) from yourTableName group by yourColumnName;
To understand the above syntax, let us create a table −
mysql> create table DemoTable2005 ( Id int, Price float ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2005 values(1,56.88); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2005 values(1,120.56); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable2005;
This will produce the following output −
+------+--------+ | Id | Price | +------+--------+ | 1 | 56.88 | | 1 | 120.56 | +------+--------+ 2 rows in set (0.00 sec)
Here is the query to get minimum value from a column wherein the corresponding column has duplicate ids −
mysql> select min(Price) from DemoTable2005 group by Id;
This will produce the following output −
+------------+ | min(Price) | +------------+ | 56.88 | +------------+ 1 row in set (0.00 sec)
Advertisements