Training
Module
Combine query results with set operators - Training
Combine query results with set operators using Transact-SQL.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
You can expand or narrow the scope of your query by including several data columns as part of your search condition. For example, you might want to:
Search for employees who either have worked more than five years at the company or who hold certain jobs.
Search for a book that is both published by a specific publisher and pertains to cooking.
To create a query that searches for values in either of two (or more) columns, you specify an OR condition. To create a query that must meet all conditions in two (or more) columns, you specify an AND condition.
To create multiple conditions linked with OR, you put each separate condition in a different column of the Criteria pane.
In the Criteria Pane, add the columns you want to search.
In the Filter column for the first column to search, specify the first condition.
In the Or... column for the second data column to search, specify the second condition, leaving the Filter column blank.
The Query and View Designer creates a WHERE clause that contains an OR condition such as the following:
SELECT job_lvl, hire_date
FROM employee
WHERE (job_lvl >= 200) OR
(hire_date < '01/01/1998')
Repeat Steps 2 and 3 for each additional condition you want to add. Use a different Or... column for each new condition.
To search different data columns using conditions linked with AND, you put all the conditions in the Filter column of the grid.
In the Criteria Pane, add the columns you want to search.
In the Filter column for the first data column to search, specify the first condition.
In the Filter column for the second data column, specify the second condition.
The Query and View Designer creates a WHERE clause that contains an AND condition such as the following:
SELECT pub_id, title
FROM titles
WHERE (pub_id = '0877') AND (title LIKE '%Cook%')
Repeat Steps 2 and 3 for each additional condition you want to add.
Combine Conditions When AND Has Precedence
Combine Conditions When OR Has Precedence
Conventions for Combining Search Conditions in the Criteria Pane
Specify Search Criteria
Training
Module
Combine query results with set operators - Training
Combine query results with set operators using Transact-SQL.
Documentation
Specify Multiple Search Conditions for One Column
Specify Multiple Search Conditions for One Column (Visual Database Tools)
Working with Empty Values - SQL Server
Working with Empty Values
SELECT @local_variable (Transact-SQL) - SQL Server
SELECT @local_variable sets a local variable to the value of an expression