Krivalar Tutorials 
Krivalar Tutorials



SQL - OR Operator

<< Previous - SQL AND operator

Next - SQL NOT operator >>






OR is a SQL operator used to fetch records that satisy one of two conditions from a database table. OR operator can be used in the WHERE clause or the HAVING clause. Each condition is separated from the other condition by OR keyword. If any one of the conditions are TRUE then only it would retrieve the record from table and return the result.

Syntax


SELECT * FROM Table-name
WHERE condition 1 OR condition 2 OR .......condition N ;



Example of OR

Consider the above example student table in collegedb.

Following SQL statement selects the all records only if either City = 'Chennai' or Age = 18.

mysql> SELECT * FROM student WHERE City = 'Chennai' OR Age = 18;
+--------+---------+------+---------+
| RollNo | Name    | Age  | City    |
+--------+---------+------+---------+
|      1 | Aruna   |   18 | Chennai |
|      4 | Markdin |   18 | Mumbai  |
|      6 | Kanika  |   18 | Chennai |
+--------+---------+------+---------+
3 rows in set (0.09 sec)

<<Previous - SQL AND operator

Next - SQL NOT operator >>









Searching using Binary Search Tree