

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pull row with lowest number in a MySQL column?
Use aggregate function MIN() along with GROUP BY for this. Here, we will display the minimum ID for NumberOfProduct . Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, NumberOfProduct int ); Query OK, 0 rows affected (0.19 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(NumberOfProduct) values(40); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(NumberOfProduct) values(40); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(NumberOfProduct) values(60); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(NumberOfProduct) values(60); Query OK, 1 row affected (0.06 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-----------------+ | Id | NumberOfProduct | +----+-----------------+ | 1 | 40 | | 2 | 40 | | 3 | 60 | | 4 | 60 | +----+-----------------+ 4 rows in set (0.00 sec)
Following is the query to pull row with lowest number in a column −
mysql> select NumberOfProduct,MIN(Id) from DemoTable group by NumberOfProduct;
This will produce the following output −
+-----------------+---------+ | NumberOfProduct | MIN(Id) | +-----------------+---------+ | 40 | 1 | | 60 | 3 | +-----------------+---------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Get row data for the lowest and highest values in a MySQL column
- Multiplying column with NULL row in MySQL?
- Find the next lowest number higher than a certain number in MySQL?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- 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 count number of NULLs in a row with MySQL?
- MySQL query to delete a record with the lowest ID?
- How can we combine ROW selection with COLUMN selection in MySQL?
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- MySQL insert a value to specific row and column
- Find lowest Date (custom) in MySQL?
- Count the same value of each row in a MySQL column?
- The Row Holding the Maximum of a Certain Column in MySQL
- MongoDB pull with positional operator?
- Find the column number with largest value for each row in an R matrix.
Advertisements