From the course: SQL Server 2008 Essential Training

Unlock the full course today

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

Creating conditions in SQL

Creating conditions in SQL - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Creating conditions in SQL

So we have this very simple SQL query, selecting these three columns from the SalesLT.Customer table in the AdventureWorksLT database. If I execute that, it's going to bring back the entire contents of that table, which is 847 rows. But I can either see by scanning through it or down here in the status bar, 847 rows. But of course, if I don't want all those rows available, if I want to filter that information, it's a very common thing. So, the way that I do it is by using the WHERE keyword. I only want to bring back that data where people have a certain last name or have a certain email address or their customer ID is in a particular range. Now it all depends on what kind of data that you're filtering on. So, for example, if I wanted to bring back information where the LastName of the person was equal to Vargas, well, if it's text I need to write it in quotes. Another single quote again here. If I execute that, I get in this case four rows coming back. It looks like my table may even…

Contents