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

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.