Lesson 5. Filtering Data

The WHERE clause is how you filter the data that you want to look at. A basic filter consists of a column name that you want to filter on and the conditions of the filter.

When we filter on string values, you have to enclose the condition in ''. Other data types do not require this, and you will learn which ones over time.

I want you to get into the habit of writing ablation testing ready queries. You will learn what that is later. For now, every query with a filter should have at least two filters. The first filter should always be setting 1 = 1.

Since you are going to have at least two filters, that means we need to tell SQL Server that we want to filter on the first AND the second condition. We do that by using the AND logic operator.

Examples

Filter On String Value

USE AdventureWorks2016

SELECT *
FROM Purchasing.Vendor
WHERE 1 = 1
AND ActiveFlag = 1

Filter On Non-String Data Type

USE AdventureWorks2016

SELECT *
FROM Purchasing.Vendor
WHERE 1 = 1
AND AccountNumber = 'RECREATI0001'

Last updated