MySQL AND & OR condition

In MySQL, you can use AND & OR condition both together with the SELECT, INSERT, UPDATE and DELETE statement. While combine these conditions, you must be aware where to use round brackets so that the database know the order to evaluate each condition.

Syntax:

snippet
WHERE condition1
AND condition2
...
OR condition_n;

Parameter

condition1, condition2, ... condition_n: It specifies the conditions that are evaluated to determine if the records will be selected.

MySQL AND OR Example

Consider a table "students", having the following data.

MySQL AND OR Condition 1

Execute the following query:

snippet
SELECT *
FROM students
WHERE (course_name = 'Java' AND student_name = 'Aryan')
OR (student_id < 2);

Output:

MySQL AND OR Condition 2
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents