×

SQL SELECT AND Operator

This SQL tutorial explains and helps us understand how to use the AND Operator in the SELECT query with examples.

The AND Operator is used to fetch the table’s records if both the given expressions are true in the query.

For example, the customer filters the plan where he selected the price between 600 and 800, including a Hotstar prime subscription. Customers can see only those plans where the price is between 600 and 800, including a Hotstar prime subscription. The customer can’t see plans that fail one of the above-given expressions.

Syntax of the SQL SELECT AND Operator is as follows:

SELECT Column_Name_1, Column_Name_2, Column_Name_3. Column_Name_4, Column_Name_5 FROM Table_Name WHERE Column_Name = Value AND Column_Name =Value;

The Column name in the expression can be the same column name or a different column name.

Let’s understand the SQL SELECT AND Operator with the help of examples.

Consider the already existing table named Diploma_Student:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakashi Patil807874788077782
202119Sopan Bhore706875758080752
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845

Example 1: Execute a query to display the student’s information where the student’s second-semester percentage is greater than 72, and department id is 1, 3, 5.

SELECT * FROM Diploma_Student WHERE Second_Sem > 72 AND Department_Id IN (1, 3, 5);

In the above SELECT AND Operator query, we displayed student’s information where the student’s second-semester percentage is greater than 72 and student department id is 1, 3, and 5. We used the IN Operator instead of the OR Operator for multiple department ids.

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202113Yash Dhull908894878590893
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
202225Akshay Agarwal858078889082845
SQL SELECT AND Operator

Example 2: Execute a query to display the student’s information where the student’s overall percentage is greater than 80, and the student’s name contains the letter ‘A’ anywhere in the name.

SELECT * FROM Diploma_Student WHERE Total > 80 AND Student_Name LIKE '%A%';

In the above SELECT AND Operator query example, we displayed the student’s information where the student’s overall percentage is greater than 80. The student’s name contains the letter ‘A’ anywhere. For pattern matching, we have used the LIKE Operator in the query.

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202225Akshay Agarwal858078889082845
SQL SELECT AND Operator

Related Topics

SQL Aggregate Operators

In SQL, the aggregate operators perform a calculation on multiple rows or multiple values of a single column and give the output a single value. Here, multiple rows of data are...

4 minutes read.

SQL Scalar Functions

TEACHER Table LCASE() Function The LCASE() function is used to return lower case values of specified column. Syntax: Select Lcase(column_name) from table_name; Example: Select Lcase(teacher_name) from teacher; Syntax: Select Lcase(column_name) from table_name [where condition]; Example: Select Lcase(teacher_name) from teacher where teacher_id=1; UCASE() Function The UCASE()...

1 minute read.

SQL Count

Structured Query Language Count() Function is used with Structured Query Language SELECT Statement. SQL Count() function returns the number of items that match the specified criteria in the SELECT statement. Count()...

2 minutes read.

How to Create Temporary Table in SQL?

How to Create Temporary Table in SQL  Introduction to Temporary Tables Temporary table is a table which is used to store temporary data that can be used further in the same client...

3 minutes read.

SQL Arithmetic Operators

This page contains all the information, learn about SQL Arithmetic Operators concept in the SQL table with the help of examples. The Arithmetic Operators is used to perform mathematical calculations on...

5 minutes read.

DML Commands in SQL

DML is an abbreviation of Data Manipulation Language. Data Manipulation Language commands in Structured Query Language manipulate the data in the database. DML commands are used to retrieve records, add records,...

4 minutes read.

SQL Auto Increment

As we all know, In SQL for unique identification, we assign a column with the primary key. But in some tables, we find difficult to differentiate a column as a...

5 minutes read.

What is SQL Injection?

Introduction to SQL Injection SQL injection is a vulnerability or a technique that might destroy the database of a website or a web application. It is one of the most widely...

4 minutes read.

SQL Right Join

The SQL Right Join query displays all the table records and similar records from the left table. The query display zero records if it doesn’t find any similar records. If...

4 minutes read.

SQL FOREIGN KEY

In this article, we will learn about the FOREIGN KEY constraints and how to define a FOREIGN KEY constraint to build the relationship between two tables. In a Relational Databases Management...

4 minutes read.

Save Point in SQL

In SQL, the classification is done into 4 languages. They are Data Definition Language (DDL)Data Manipulation Language (DML)Transaction Control Language (TCL)Data Control Language (DCL) Save Point falls under the Transaction Control Language....

4 minutes read.

SQL Insert multiple rows

This article will deal with a new insertion method in SQL which inserts multiple rows at a time. Multiple records can be inserted at a time into a specific table with...

4 minutes read.

Update Query in SQL

Update is an SQL command that is used to modify the data that in already present in database. Update is a command of DML. DML means Data Manipulation Language. Basically,...

3 minutes read.

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.

How to create a database in SQL?

How to create a database in SQL It is very necessary to create a database in order to store the data into the database.Database name must always be unique.SQL does not...

6 minutes read.

SQL Cloning Tables

Cloning a Table: To create a copy of the table. To perform the operations, without affecting the actual table. Steps for creating a Cloning Table: Step 1: Empty Table Creation The syntax for Creating...

3 minutes read.

Difference between Delete, Drop and Truncate in SQL

What is the Delete command in SQL? In DML (Data Manipulation Language), we use the delete command that allows us to delete the some entries and modify the databases in SQL....

4 minutes read.

SQL ORDER BY

SQL ORDER BY The SQL ORDER BY clause is used to sort the data stored in tables in the database. The sorting can be done in an ascending way, descending way,...

5 minutes read.

SQL Data Control Language

Data Control Language decides to whom should (which user) permit access privileges. GRANT and REVOKE are the commands of DCL. GRANT: It gives privileges to user. REVOKE: It takes back privileges from granted...

1 minute read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.