mysql where multiple values – 2 ways to use multiple values in WHERE clauses

mysql where multiple values To fetch fields with multiple values, use WHERE, IN(), LIKE with OR in MySQL.

mysql where multiple values

To select multiple values, you can use where clause with OR and IN operator. SELECT FROM WHERE multiple conditions.

MySQL Select Multiple VALUES

WHERE id = 8 or id = 9

using IN()

WHERE id in (8,9)

Using OR

mysql> select *from members where member_id = 45 or member_id = 98;

Don’t Miss : autocomplete textbox using jquery from database php

Using IN

mysql> select *from members where member_id in(45,98);

MySQL query with LIKE operator for multiple values, with aggregate

Read Also:  Simple JQuery Ajax Request Example with Laravel 6

WHERE member_type REGEXP '^(car|bus)'

Insert multiple rows using INSERT

mysql> insert into students(id, account_nm, profilenm)
       values(1,'Ravi','Rak'),
       (2,'Kano','Rak');

mysql> select * from students;
+------+------------+-----------+
| id   | account_nm | profilenm |
+------+------------+-----------+
|    1 | Ravi       | Rak       |
|    2 | Kano       | Rak       |
+------+------------+-----------+

Insert Multiple Rows from SELECT

mysql> insert into students2(id, account_nm, profilenm)
       select id, account_nm, profilenm
       from students;

mysql> select * from students2;
+------+------------+-----------+
| id   | account_nm | profilenm |
+------+------------+-----------+
|    1 | Ravi       | Rak       |
|    2 | Kano       | Rak       |
+------+------------+-----------+

Insert Multiple Rows Without Duplicate

mysql> create table students(id int primary key,
       account_nm varchar(255),
       profilenm varchar(255));

mysql> insert ignore into students(id, account_nm, profilenm)
            values(1,'Ravi','Rak'),
            (1,'Ravi','Rak');

mysql> select * from students;
+----+------------+-----------+
| id | account_nm | profilenm |
+----+------------+-----------+
|  1 | Ravi       | Rak       |
+----+------------+-----------+

I hope you get an idea about mysql where multiple values.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.