From the course: Microsoft SQL Server 2016: Query Data

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using EXISTS

Using EXISTS - SQL Server Tutorial

From the course: Microsoft SQL Server 2016: Query Data

Start my 1-month free trial

Using EXISTS

- [Instructor] In this lesson, we're going to take a look at the use of the EXISTS keyword. Now EXISTS is a way of us running some kind of a check, it's a predicate basically, and we check to see if a value exists within a results set. And in this case what we're going to do in our first query is we're going to take a look to see if we can find any customer account numbers from customers who have placed orders online, and so in order to do this we make use of subqueries. And in the previous lesson we took a look at subqueries so you should understand how they work, and it's a nested query. So we'll run the nested query to return a result set and then we are going to in the outer query use the EXISTS keyword to see if the account number exists in the results set and if it does we return it. So let's kind of look at what we have here for our query. Let's look at the nested query first. We're going to select all the fields from the sales order header table, and again we're just using…

Contents