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

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       |
+----+------------+-----------+

multiple where condition in sql

In SQL, you can use the WHERE clause to filter records based on one or more conditions. To specify multiple conditions in a WHERE clause, you can use logical operators such as AND and OR. Here’s an example of how to use multiple WHERE conditions in a SQL query:

SELECT column1, column2, column3
FROM my_table
WHERE column1 = 'value1' AND column2 = 'value2'

In this example, we are selecting columns column1, column2, and column3 from the my_table table. We are using the WHERE clause to filter the records based on two conditions:

column1 = ‘value1’: This condition will only return records where column1 is equal to the value ‘value1’.
column2 = ‘value2’: This condition will only return records where column2 is equal to the value ‘value2’.

We are using the AND operator to combine these two conditions, which means that both conditions must be true for a record to be returned.

You can also use the OR operator to specify multiple conditions where at least one of them needs to be true to select a record. Here’s an example:

SELECT column1, column2, column3
FROM my_table
WHERE column1 = 'value1' OR column2 = 'value2'

In this example, we are using the OR operator to specify two conditions. This query will return all records where either column1 is equal to the value ‘value1’ or column2 is equal to the value ‘value2’.

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.

Leave a Comment