Module 2: Filter PDF Data Using WHERE clause - Part 3
Previous Tutorial - Next Tutorial
The WHERE clause becomes really interesting when we consider combining more than one field to filter a result. The WHERE clause can be combined with AND/OR and NOT logical operators to create more complex conditions. The AND/OR operators are used to filter records based on more than one condition. So basically they call the boolean logical operators.
The AND operator displays a record if and only if all the specified conditions are evaluated to true. So this table shows all possible combinations of the condition. Let's see this AND operator practically. Again back to the SQL server management studio. Now from this person table, I want to find that person whose first name is Kevin and last name is Brown by using the AND operator. So let's see how we can use this And Boolean logical operator in the WHERE clause(WHERE FirstName = 'Kevin' AND LastName = 'brown'). If I execute this query, I will get that person whose first name is Kevin and the last name is Brown.
So the same way you can use the OR operator. In OR operator, it displays only those records if and only if the specified condition evaluates to true. So here in the table, you can see that in any case, if one of the conditions is evaluated to true, then the end result will also evaluate to true. That means you will get the data from the table if any of the conditions evaluate to true. In this query, if I write OR operator over here like (WHERE FirstName = 'Kevin' OR LastName = 'brown') and if I execute this query, it gives me that person whose first name is either Kevin or last name is either Brown.
So the NOT operator displayed a record if the condition is not true. So for example, in this person's table, I want to list out that person whose title is not Mr. and not Mrs. So let's see how we can write the WHERE clause using the NOT operator(WHERE NOT Title = 'Mr.' AND NOT Title = 'Ms.').
If I execute this query, I will get that person whose title is not Mr and whose title is not Ms. So in the next slide, we will learn about the ORDER by clause, which will help us to identify which column to use to sort the resulting data.
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