Back to Top

Sunday 17 March 2013

SQL: OR Command

In SQL, we have seen the use of AND command, to set multiple condition when performing a database transaction. But when we use AND, that means it's a mandatory condition. The transaction will provide output, only when all the conditions will be satisfied. But, what about an optional condition? Do SQL have any provision for that? The Answer is yes. SQL Do have command named OR to set optional condition.

Syntax: SELECT [column_name] FROM [table_name] WHERE [condition_1] OR [condition_2];

Here, output will come if [condition_1] OR [condition_2] OR both satisfied. That means, it is SELECT [column_name] FROM [table_name] WHERE [condition_1] OR [condition_2] OR both applied.


Example:

Again, we will use the same table, to see the usage of  OR command.
Table Name:

Employee Details ( employee_details)
Column Names:
Employee ID ( emp_id), 

Employee Name (emp_name), 
Employee Address (emp_address) and
Employee Role: (emp_role).

Table:  employee_details 


Now, using OR command, we will SELECT those tuple, WHERE emp_role is 'Developer' or 'Business Analyst'.
So, the query will be :

SELECT * FROM employee_details WHERE emp_role = 'Developer' OR emp_role = 'Business Analyst';

Result:











0 Responses to “ SQL: OR Command ”

Post a Comment

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar