
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to select row when column must satisfy multiple value in MySQL?
For this, you can use GROUP BY HAVING clause along with IN(). Let us first create a table −
mysql> create table DemoTable1885 ( FirstName varchar(20), Subject varchar(50) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1885 values('John','MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1885 values('John','MongoDB'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1885 values('Carol','MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1885 values('David','Java'); Query OK, 1 row affected (0.00 sec)
Display some records in the table using insert command −
mysql> select * from DemoTable1885;
This will produce the following output −
+-----------+---------+ | FirstName | Subject | +-----------+---------+ | John | MySQL| | John | MongoDB| | Carol | MySQL| | David | Java | +-----------+---------+ 4 rows in set (0.00 sec)
Here is the query to select row when column must satisfy multiple value:
mysql> select FirstName from DemoTable1885 where Subject IN('MySQL','MongoDB') group by FirstName having count(*)=2;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | +-----------+ 1 row in set (0.00 sec)
- Related Articles
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- How to select the sum of the column values with higher value in reach row with MySQL?
- MySQL query to select a random row value (Id and Name) having multiple occurrences (Name)?
- SELECT where row value contains string in MySQL?
- How to select last row in MySQL?
- How to select the maximum value of a column in MySQL?
- Show column value twice in MySQL Select?
- How to select distinct value from one MySQL column only?
- How to add a column from a select query but the value from the new column will be the row count of the MySQL select query?
- MySQL SELECT to sum a column value with previous value
- How to select next row pagination in MySQL?
- MySQL insert a value to specific row and column
- How to execute multiple select queries in MySQL ?
- Select multiple columns and display in a single column in MySQL?
- MySQL Select when a grouped record has multiple matching strings?

Advertisements