- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Match the elements of an array in a MySQL query
Let us first create a table table −
mysql> create table DemoTable1523 -> ( -> Id int, -> Value int -> ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1523 values(1,56); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1523 values(2,78); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1523 values(1,34); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1523 values(2,45); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1523 values(1,99); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1523;
This will produce the following output −
+------+-------+ | Id | Value | +------+-------+ | 1 | 56 | | 2 | 78 | | 1 | 34 | | 2 | 45 | | 1 | 99 | +------+-------+ 5 rows in set (0.00 sec)
Following is the query to match the elements of array. Here, we are selecting id with matching values 34, 99, and 56 −
mysql> select Id from DemoTable1523 -> where Value IN ('34','99','56') -> group by Id -> having count(*)=3;
This will produce the following output −
+------+ | Id | +------+ | 1 | +------+ 1 row in set (0.00 sec)
- Related Articles
- How to query an Array[String] for a Regular Expression match?
- MongoDB query to filter object where all elements from nested array match the condition
- MongoDB query to match and remove element from an array?
- MongoDB query to match documents that contain an array field
- MongoDB query to match documents whose _id is in an array as part of a subdocument?
- Check if an array contains the elements that match the specified conditions in C#
- MySQL query to find a match and fetch records
- Passing an array to a query using WHERE clause in MySQL?
- MySQL query to match any of the two strings from column values
- MongoDB query to match each element in a documents array to a condition?
- MongoDB query to change order of array elements?
- MySQL query to get the count of all the elements in the field?
- MongoDB query to match documents with array values greater than a specific value
- MongoDB query to remove array elements from a document?
- Can you assign an Array of 100 elements to an array of 10 elements in Java?

Advertisements