WHERE clause with Multiple Conditions

The MySQL And, Or, Not, operators can be combined in a SELECT, INSERT, UPDATE, or DELETE statement.

When combining these operators, it is important to use parentheses so that the database knows knows what order to evaluate each condition.

Syntax

WHERE condition 1 AND condition2 ... OR condition_n;

Let’s look at an example that combines the AND, OR conditions in a SELECT statement. To do this, Click show query box ( to edit the query)

Then execute the query below;

Select * from  products where price >2000 and quantity=5

Look at the following example will to display all the Male students who were joined in DCA course.

SELECT * FROM 'students' WHERE course='DCA' and gender = 'MALE'

If we replace and with or operator in the above example, it will display all the Male students of all courses as well as, all the students joined in DCA course.

Select * From `students` where course ='DCA' or gender= 'Male'

Suppose, we want to display students name of all students who were joined in DCA and HDCA course, the query will be,

select * from `students` where course='DCA' or course='HDCA'

Let’s look at the following example with AND and OR operator ,

SELECT * FROM `STUDENTS` WHERE (course = 'DCA' or course = 'HDCA') and gender = 'FEMALE'

Displays all the students who were joined either in DCA or HDCA course.

The following example explains using NOT operator.

select * FROM `students` WHERE not course = 'DCA'

Displays all the students expect those joined in DCA course.