- 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
Find the next lowest number higher than a certain number in MySQL?
For this, use aggregate function MIN() along with WHERE clause. Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 11 | | 9 | | 10 | | 12 | +--------+ 4 rows in set (0.00 sec)
Following is the query to find the next lowest number higher than a certain number in MySQL −
mysql> select min(Number) from DemoTable where Number > 10;
This will produce the following output −
+-------------+ | min(Number) | +-------------+ | 11 | +-------------+ 1 row in set (0.00 sec)
Advertisements