Module 2: Filtering Data with WHERE Clause Overview
Previous Tutorial - Next Tutorial
We are somewhat familiar with the basic functionality of the SELECT statement, it will return the required result from the query table. But sometimes there is a situation when we want to restrict the query results to a specified condition. Filtering data is one of the most fundamental aspects of T-SQL querying.
Almost every query that you write involves some form of filtering. We will be going to learn about various condition operators used with the WHERE clause, such as comparison operators, range operators, etc. So this is the general syntax of the WHERE clause and it is followed by some search criteria or a predicate. It returns only those rows for which the predicate evaluates to true. So, for example, in this person's table, I want to find the person whose last name is Galvin.
So if I write this query, then it will give me the result where I have highlighted some records which I want to filter out. So when I apply the WHERE predicted something like this, then it will give me this result. So here I have used the equal to the operator in the WHERE clause I can use the different operators to filter out the result.
Here are the different operators that I can use with the WHERE clause. They are used to specify conditions in an inner SQL statement. For example, this is the comparison operator in the previous query. In the previous slide, we have used this equal to operator, which checks if the value of the next left expression and a right expression are equal or not. If they are equal, then the condition becomes true and it will return the result.
In the same way, we have a range operator. It will check if the column value falls within a certain range or not using the between operator here, using the (<)Less-than operator and (>)greater-than operator. So, if the specified value falls within the range, then it will return the result.
In the same way, we can use the IS, NULL operator, to compare with the null value. So null has some special meaning in SQL Server. Null means unknown or missing information. NULL is a result keyword in the SQL server.
So comparing any value with null will result in an unknown and then we have a like operator, so using like you can search for values that start or end with specified characters, you can also search for a specific character contain within the specified string with the help of wild card such as percentage sign and underscore.
So rather than reading this slide, let's jump into the code and perform each and every operator practically. We will start by looking at how to use the WHERE clause with a single condition. So first, let's take the equal to operator.
Web API for developers Free Trial Offline SDK
Here's SQL video tutorial:
Other useful tutorials:
- General SQL Introduction
- Module 1: Getting Started with SQL Server
- Module 1: SQL Server Management
- Module 1: Essential SQL Commands
- Module 1: SQL Introduction Essentials
- Module 2: Learning SQL Overview
- Module 2: Logical Query Processing Order
- Module 2: Select Statement Fundamentals
- Module 2: Filtering Data with WHERE Clause Overview
- Module 2: Filter Data with WHERE Clause - Part 1
- Module 2: How to Filter Data with WHERE Clause - Part 2
- Module 2: Filter PDF Data Using WHERE clause - Part 3
- Module 2: Sorting Data Using ORDER BY Clause
- Module 2: Grouping Data with GROUP BY Clause Part 1
- Module 2: Grouping Data with GROUP BY Clause Part 2
- Module 2: Grouping Data with GROUP BY Clause Part 3
- Module 2: Limiting Data With TOP Clause
- Module 2: Summary and Quiz
- Module 3: SQL Joins and SET Operators
- Module 3: Understanding Inner Join
- Module 3: Understanding Outer Join
- Module 3: Cross Join Explained
- Module 3: Self Join Explained
- Module 3: UNION and UNION ALL
- Module 3: INTERSECT and EXCEPT
- Module 3: Understanding Sub-Queries
- SQL Analytic Functions