Home » SQL

How to use AND/ OR Operator in SQL?

In this article, we are going to discuss SQL. If You know what is AND / Or Operator, then it became very easy to understand; If you know any of the programming languages then officially you know what are these operators and how they work. So, in this article, we are going to discuss the use of AND / OR operator in SQL queries.
Submitted by Bharti Parmar, on October 29, 2018

Basically, AND / OR operator is used to retrieving the record from the database. If we give more than one conditions by using AND Operator, then it retrieves the data from the database when both the conditions are true. And if we use OR operator it retrieves data from the database in both cases either one or more condition is true. Here, in this example we use table 1 for retrieving data using AND, OR operator:

Example:

Table 1:

Student_ID Student_Name Dept Branch Course
15011 AmanGautam CSE IT B.tech
15028 AtulAnand CSE CS B.tech
15032 Bharti Parmar CSE CS B.tech
15068 Partha Biswas CSE IT B.tech

1) We have to find the Student_Name whose Dept is CSE and Branch is CS using SQL query.

SQL | AND/OR Query Example 1

2) We have to find the Student_Name whose Dept is CSE OR Branch is CS using SQL query.

SQL | AND/OR Query Example 2

Table 2:

Student_ID HOD Dean
15011 Shivani rajpoot Aditya sikarwar
15028 Sanchita nayak Aditya Sikarwar
15032 Sanchita nayak RK sharma
15068 Shivani rajpoot RK sharma

Here, in this example we use two table which are join by primary and foreign key for retrieving data using AND OR operator.

1) We have to find the Student_Name, HOD whose Dean is R. K Sharma and Branch is CS using SQL query.

SQL | AND/OR Query Example 3

2) We have to find the Student_Name, Dean where HOD is shivani rajpoot using SQL query.

SQL | AND/OR Query Example 4

Conclusion:

In this article, we are using AND OR operator to retrieve data from the database/table. Also, we see the example of how to retrieve data from the single table or more than one table. I hope you understand the concept; if you have any query, feel free to ask in the comment section. I will be trying to give you an answer of your question as soon as possible. We will know more about SQL in the upcoming article.




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.