Tutorials

SQL Clause and Operator


SQL OR


IN SQL OR operator is used along with WHERE clause to filter the search record based on multiple conditions like AND.

All those rows are returned that meet any of the conditions in OR.

 

Syntax on SQL OR operator

SELECT [*|columns]
FROM table_name
WHERE condition1 OR condition2 OR .... conditionN;

Example on SQL OR

We will use tih_Courses table for demonstration purpose

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
005 Blogging Tutorial Puja  Online
006 JSP Alok Pandey Online and Offline
007 Servlet Mukesh Tiwari Online and Offline

Query 1: Write a sql query to select all those rows whose professor is Mukesh Tiwari or Puja.


SELECT * 
FROM tih_Courses 
WHERE Professor = 'Mukesh Tiwari' OR Professor = 'Puja';

On successfully executing the above query, we will get following result:

 

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
005 Blogging Tutorial Puja  Online
007 Servlet Mukesh Tiwari Online and Offline
Query-2: Write a sql query to select all the rows from table where course id is 002 0r 007 or professor is Alok Pandey

SELECT * 
FROM tih_Courses 
WHERE Course_ID= 002 OR Course_ID= 007 OR Professor = 'Alok Pandey';

On successfully executing the above query, we will get following result:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
002 Java Rajneesh Shukla Online and Offline
006 JSP Alok Pandey Online and Offline
007 Servlet Mukesh Tiwari Online and Offline

 



Please Share this page
Views : 98
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!