
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Selecting Records Within a Range and With Conditions on Two Columns in MySQL
For this, use where clause. Let us first create a table −
mysql> create table DemoTable -> ( -> Number1 int, -> Number2 int -> ); Query OK, 0 rows affected (3.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(40,50); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable values(100,59); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable values(400,500); Query OK, 1 row affected (0.40 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------+---------+ | Number1 | Number2 | +---------+---------+ | 40 | 50 | | 100 | 59 | | 400 | 500 | +---------+---------+ 3 rows in set (0.00 sec)
Here is the query to select records with a range condition on two columns −
mysql> select *from DemoTable where Number1 >=51 and Number2 <=1000;
Output
This will produce the following output −
+---------+---------+ | Number1 | Number2 | +---------+---------+ | 100 | 59 | | 400 | 500 | +---------+---------+ 2 rows in set (0.00 sec)
Advertisements