SQL Predicates

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:01:00

Comparison

Comparison operators in SQL Server are used to compare values in expressions and return a Boolean result (true or false) based on the specified condition. Common comparison operators include "=", "<>", ">", "<", ">=", and "<=".

Example

SELECT * FROM Employees WHERE Salary > 50000;

LIKE

The LIKE operator in SQL Server is used to filter rows based on a specified pattern using wildcard characters such as '%' (matches zero or more characters) and '_' (matches a single character). It is commonly used with the WHERE clause to perform partial string matching.

Example

SELECT * FROM Products WHERE ProductName LIKE 'App%';

BETWEEN

The BETWEEN operator in SQL Server is used to filter rows within a specified range of values. It is inclusive, meaning it includes the start and end values in the range.

Example

SELECT * FROM Orders WHERE OrderDate BETWEEN '2023-01-01' AND '2023-03-31';

IN

The IN operator in SQL Server is used to filter rows where a specified column's value matches any value in a list of values. It's a shorthand way of combining multiple OR conditions.

Example

SELECT * FROM Customers WHERE Country IN ('USA', 'Canada', 'UK');

EXISTS

The EXISTS operator in SQL Server is used to check for the existence of rows in a subquery. It returns true if the subquery returns at least one row; otherwise, it returns false.

Example

SELECT * FROM Orders WHERE EXISTS (SELECT 1 FROM OrderDetails WHERE Orders.OrderID = OrderDetails.OrderID);

IS NULL (/INTEGER/DECIMAL/FLOAT...)

The IS NULL operator is used to filter rows where a specified column's value is NULL, indicating the absence of a value. It can be applied to columns of various data types, including INTEGER, DECIMAL, FLOAT, and others.

Example

SELECT * FROM Employees WHERE DepartmentID IS NULL;
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this