MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL AND & OR Operator

The MySQL allows you to use AND & OR operator togather to display the records from the table. While combine these operator, you must be aware how to use round brackets precision to evaluate each condition.

MySQL AND & OR Operator Syntax

To filter a record if any of the conditions separated by OR is TRUE, use the following syntax:

Syntax

SELECT col1, col2, ...
FROM tablename
WHERE condition1 AND condition2 OR condition3 ...;  

Parameters:

tablename: The table name from which you want to fetch the records.

condition: To specifies multiple conditions, either of the condition must be true to select records with OR or both condition must be true with AND.

MySQL AND & OR OPERATOR example

The following MySQL statement is used to filter a record if any of the conditions separated by OR is TRUE or both of the conditions separated by AND is TRUE:

Example

SELECT firstName, lastName, address FROM tblCustomerLoan 
WHERE cellNo = 7897897890 AND lastName = 'Singh' OR  panNo = 'LKJHG1232U';

Note:

In the above example, we are showing how to use the OR operator to filter records based on any of the conditions separated by OR is TRUE or both of the condition separated by AND is TRUE in SELECT statement.

You can use MySQL Command Line Client to filter records based on OR or AND operator. It will look like this: