Home > Database > Mysql Tutorial > body text

How to use multiple conditions on the same column while getting data as output?

WBOY
Release: 2023-09-09 16:53:05
forward
1536 people have browsed it

How to use multiple conditions on the same column while getting data as output?

Here's how we write a query that returns only records that match multiple criteria on the same column

By using "OR" logic Operator

As we all know, MySQL's "OR" operator compares two expressions and returns TRUE if one of the expressions is TRUE. The following example demonstrates how to use the "OR" operator for multiple conditions on the same column

mysql> Select * from Student WHERE Name = 'Gaurav' OR Name = 'Aarav';

+------+--------+---------+-----------+
| Id   | Name   | Address | Subject   |
+------+--------+---------+-----------+
| 1    | Gaurav | Delhi   | Computers |
| 2    | Aarav  | Mumbai  | History   |
+------+--------+---------+-----------+

2 rows in set (0.00 sec)
Copy after login

By using the WHERE IN(…) clause

The WHERE IN(…) clause is also used for the above purposes. It can be used in queries with multiple conditions on the same column as shown below -

mysql> Select * from Student WHERE Name IN ('Gaurav','Aarav');

+------+--------+---------+-----------+
| Id   | Name   | Address | Subject   |
+------+--------+---------+-----------+
| 1    | Gaurav | Delhi   | Computers |
| 2    | Aarav  | Mumbai  | History   |
+------+--------+---------+-----------+

2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to use multiple conditions on the same column while getting data as output?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!