Logical Operators - SQL (Samples)
Logical Operators - SQL (Samples)
SQL logical operators are used to test for the truth of the condition. A logical operator like the Comparison operator returns a
boolean value of TRUE, FALSE, or UNKNOWN. In this article, we will discuss different types of Logical Operators.
Logical operators are used to combine or manipulate the conditions given in a query to retrieve or manipulate data .There are some
logical operators in SQL like OR, AND etc.
Operator Meaning
Example:
In the below example, we will see how this logical operator works with the help of creating a database.
Query
In this step, we will create the table employee inside the xstream_db database.
Query
emp_city VARCHAR(255),
emp_country VARCHAR(255),
Create Table
In order to insert the data inside the database, we need to use the INSERT operator.
Query
Insert Value
Output
employee Table
AND Operator
The AND operator is used to combines two or more conditions but if it is true when all the conditions are satisfied.
Query
Output
output
IN Operator
It is used to remove the multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE. and We can also use NOT IN to
minimize the rows in your list and any kind of duplicate entry will be retained.
0 seconds of 15 secondsVolume 0%
Query
SELECT * FROM employee WHERE emp_city IN ('Allahabad', 'Patna');
Output
output
NOT Operator
Query
Output
output
OR Operator
The OR operator is used to combines two or more conditions but if it is true when one of the conditions are satisfied.
Query
Output
output
LIKE Operator
In SQL, the LIKE operator is used in the WHERE clause to search for a specified pattern in a column.
Query
Output
output
BETWEEN Operator
The SQL BETWEEN condition allows you to easily test if an expression is within a range of values (inclusive).
Query
Output
output
ALL Operator
The ALL operator returns TRUE if all of the subqueries values matches the condition.
Query
Output
output
ANY Operator
Query
SELECT * FROM employee WHERE emp_id = ANY
Output
EXISTS Operator
In SQL,Exists operator is used to check whether the result of a correlated nested query is empty or not.
Query
Output
output
SOME Operator
In SQL, SOME operators are issued with comparison operators (<,>,=,<=, etc) to compare the value with the result of a subquery.
Query
Output
output