

- 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
Should I use a loop or 'OR' operator to query a bunch of stuff at a fast pace In MYSQL?
For faster querying, you need to use MySQL IN(). Let us first create a table −
mysql> create table DemoTable1538 -> ( -> ClientId int, -> ClientName varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1538 values(101,'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1538 values(102,'Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1538 values(103,'Bob'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1538 values(104,'Adam'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1538;
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Chris | | 102 | Robert | | 103 | Bob | | 104 | Adam | +----------+------------+ 4 rows in set (0.00 sec)
Following show we can query multiple values quickly −
mysql> select * from DemoTable1538 where ClientId IN(101,103,104);
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Chris | | 103 | Bob | | 104 | Adam | +----------+------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Can I query on a MongoDB index if my query contains the $or operator?
- MySQL to Implementing OR operator in a WHERE clause?
- How to multiple insert or batch insert at a time in MySQL query?
- Fetch a specific record using a single MySQL query with AND & OR operator
- When should I use a composite index in MySQL?
- Priority of AND and OR operator in MySQL select query?
- Which one should I use? The datetime or timestamp data type in MySQL?
- How can I avoid too many OR statements in a MySQL query?
- Can we use WHERE, AND & OR in a single MySQL query?
- Can I insert two or more rows in a MySQL table at once?
- Should I use MySQL enum or tinyint for fields having values 1 and 0?
- MongoDB query to implement OR operator in find()
- When to use i++ or ++i in C++?
- How to use sizeof() operator to find the size of a data type or a variable in C#
- How should I pass a matplotlib object through a function; as Axis, Axes or Figure?
Advertisements