MSSQLTips.com · March 01, 2023
How to use the SQL WHERE Clause with Examples
Using the AdventureWorks2017 sample database, this tutorial demonstrates how the WHERE clause restricts rows retrieved, inserted through a SELECT statement, updated or deleted in SQL Server. Examples progress from simple equality predicates to conditions involving multiple columns and related tables.
The article covers AND and OR, IN, EXISTS and NOT EXISTS, NULL checks, filtering joined tables, LIKE patterns and BETWEEN ranges. It illustrates how subqueries and table aliases can express more specific filtering requirements, providing a practical reference for writing T-SQL statements that target the intended records.
Related reading
- Download Free SQL Server Daily Checklist ScriptsMSSQLTips.com
- Load JSON into SQL Server TableMSSQLTips.com
- T-SQL in One HourMSSQLTips.com
- Natural Language Query for SQL ServerMSSQLTips.com
- SQL Developer Interview QuestionsMSSQLTips.com
- Ways to Return Result Sets with SQL Server Stored ProceduresMSSQLTips.com
- SQL Server Management Studio 21 (SSMS) Quick Start GuideMSSQLTips.com
- Select SQL Server Data Between Two DatesMSSQLTips.com
- SSIS in One Hour: Hands-On TutorialMSSQLTips.com
- An overview of SQL Server monitoring toolsSQL Shack
- SQL Script for SQL Server Table and Column PropertiesMSSQLTips.com
- Data Wrangling in SQL Server for Cleaning, Transforming and Merging DataMSSQLTips.com
- Implicit Conversion Concerns for SQL Server PerformanceMSSQLTips.com
- Towards Data Quality: An Overview of SQL Server Data Quality SolutionsTech Blog
- Working with Date and Time Data Types in SQL ServerMSSQLTips.com
- Learn SQL: Insert multiple rows commandsSQL Shack
- Getting started with SSIS External Configuration FileMSSQLTips.com
- SSIS Interview Questions and Answers for Developers and DBAsMSSQLTips.com
- Fixing Cannot Convert Between Unicode and Non-Unicode String Data Types in SSISMSSQLTips.com
- Migrate Data from SQL Server to MongoDB using SSISMSSQLTips.com
- Learn SQL standard deviation functionSQL Shack
- An overview of the SQL GROUP BY clauseSQL Shack
- SSIS Bad Habits: Decreasing SSIS Package PerformanceMSSQLTips.com
- Using parameterized queries to avoid SQL injectionSQL Shack
- SSIS Bad Habits: Inefficient Data Staging Strategies - Part 2MSSQLTips.com
- xp_cmdshell and sp_xp_cmdshell_proxy_account stored procedures in SQL ServerSQL Shack
- SSIS Bad Habits: Slow lookup transformationsMSSQLTips.com
- SSIS Bad Habits: Wrong OLE DB components configurationMSSQLTips.com
- SSIS Bad Habits: Inefficient Data Staging StrategiesMSSQLTips.com
- SSIS Bad Habits: Using Sort and Merge Join ComponentsMSSQLTips.com
- SSIS Extension for Visual Studio 2022Stack Overflow
- An overview of DIFFERENCE and SOUNDEX SQL functionsSQL Shack
- Import flat files into seperate SQL Server Tables using SSISStack Overflow
- Getting started with SQL Server CLR functionsSQL Shack
- Why is the SSIS variable not passing the milliseconds part into the query?Stack Overflow
- How to using STRING_SPLIT within an SSIS OLE DB Source SQL Command when the database compatibility level is set to is set to SQL Server 2008?Stack Overflow
- Is it Possible to Load data to MongoDB Using SSIS?Stack Overflow
- SSIS, query Oracle table using ID's from SQL Server?Stack Overflow
- Popular free SQL online compilersSQL Shack
- How to write subqueries in SQL?SQL Shack
- An overview of the SQL Server ISNUMERIC functionSQL Shack
- Migrating SQL Server graph databases to ArangoDBSQL Shack
- Different approaches to execute Python in SQL ServerSQL Shack
- Working with parameters in the sp_executesql stored procedureSQL Shack
- Export indexes and constraints from SQL Server graph databases to Neo4jSQL Shack
- Microsoft SQL Server Gurus you should followTech Blog
- Migrating SQL Server graph databases to Neo4jSQL Shack
- Import data from MongoDB to SQL Server using SSISSQL Shack
- SSIS packages automation toolsTech Blog
- Nine features that made SQL Server more than a traditional DBMSTech Blog
- Building databases using BimlSQL Shack
- Building full-text indexes using the Sphinx search engineSQL Shack
- Getting started with Sphinx search engineSQL Shack
- SQL Server JSON functions, a bridge between NoSQL and relational worldsSQL Shack
- Biml alternatives: Building SSIS packages programmatically using EzAPISQL Shack
- Biml alternatives: Building SSIS packages programmatically using ManagedDTSSQL Shack
- Monitoring activities using sp_WhoIsActive in SQL ServerSQL Shack
- SSIS: Execute T-SQL Statement Task vs Execute SQL TaskSQL Shack
- SQL Server functions for converting a String to a DateSQL Shack
- A SQL join on multiple tables: overview and implementationSQL Shack
- An overview of the SQL cursor @@FETCH_STATUS functionSQL Shack
- Yet another bunch of SQL string functionsSQL Shack
- Linking relational databases with OLAP cubesSQL Shack
- An overview of SQL String FunctionsSQL Shack
- An overview of the SQL Server ProfilerSQL Shack
- An overview of the Data Profiling task in SSISSQL Shack
- SQL OFFSET FETCH Feature: Loading Large Volumes of Data Using Limited Resources with SSISSQL Shack
- Execute SQL Task in SSIS: Output Parameters vs Result SetsSQL Shack
- Execute SQL Task in SSIS: SqlStatementSource Expressions vs Variable Source TypesSQL Shack
- SSIS OLE DB Destination vs SQL Server DestinationSQL Shack
- SSIS OLE DB Source: SQL Command vs Table or ViewSQL Shack
- C# - Extract objects from SQL CommandData Developers
- Fast load error output doesn't redirect entire batchStack Overflow