
- 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
MySQL to Implementing OR operator in a WHERE clause?
The OR operator gives true result when any one operand is true. Let us now see an example and create a table −
mysql> create table DemoTable663(ClientId int,ClientName varchar(100),ClientAge int); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable663 values(100,'Chris',45); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable663 values(101,'Robert',29); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable663 values(102,'John',45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable663 values(103,'Chris',35); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable663 values(104,'Sam',45); Query OK, 1 row affected (0.72 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable663;
This will produce the following output −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 100 | Chris | 45 | | 101 | Robert | 29 | | 102 | John | 45 | | 103 | Chris | 35 | | 104 | Sam | 45 | +----------+------------+-----------+ 5 rows in set (0.00 sec)
Following is the query to implement OR operator −
mysql> select *from DemoTable663 where ClientName='Chris' OR ClientAge=45;
This will produce the following output −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 100 | Chris | 45 | | 102 | John | 45 | | 103 | Chris | 35 | | 104 | Sam | 45 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL XOR operator with IN clause?
- How to add a where clause in a MySQL Insert statement?
- Get current year in MySQL WHERE clause?
- Passing an array to a query using WHERE clause in MySQL?
- How to use MySQL VIEW with WHERE clause?
- Get all results using WHERE clause in MySQL?
- Update with multiple values in MySQL WHERE clause
- Using the entire expression in MySQL WHERE clause?
- How to use MySQL Date functions with WHERE clause?
- How to update multiple rows using single WHERE clause in MySQL?
- MySQL automatic string to integer casting in WHERE clause to fetch a specific id
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- Can we use WHERE clause inside MySQL CASE statement?
- Can we fetch multiple values with MySQL WHERE Clause?
- Conditional WHERE clause in MySQL stored procedure to set a custom value for NULL values

Advertisements