SQL Training Online

  • Training Courses
  • Beginner Book
  • Blog

June 8, 2012 by Joey Blue Leave a Comment

SQL Where

The SQL Where clause in the SQL Language allows you to filter data when you query a database.

Let’s look at the following query that gets data from the customer table:

select * from customer; 

Here are the results:

SNAGHTML12455244

Now, I only need to get the “Dell” customers.  In order to do that, I have to use the where clause.

Let’s add that to the query:

select * from customer where customer_company='Dell'; 

When I execute this query, I get the following results:

SNAGHTML12483938

So I have filtered the records from 6 down to 2.

Notice the following part of the query:

customer_company='Dell'; 

The red part is how Microsoft SQL Server represents a string.  It knows it is a string, because of the single tick (‘) marks.

All strings need to be enclosed in these.

Let’s show an example where we want everyone except for Dell customers:

select * from customer where customer_company != 'Dell'; 

Instead of using the “=” sign, we use the “!=” which says “Not Equal”.

Here are the results:

SNAGHTML124cd1de

We have filtered out the 2 Dell records.

That is the basics of the where clause.

Please leave any comments or questions below.

Related

Filed Under: SQL Training Tagged With: Beginning SQL, SQL Where

Leave a Question, Comment, or Reply. All are welcome! Cancel reply

Recent Posts

  • SQL Database Normalization – 1NF, 2NF, 3NF, and 4NF
  • SQL Joins Tutorial for Beginners – Inner Join, Left Join, Right Join, Full Outer Join – SQL Training Online
  • Zillow House Price Analysis from CSV Archive – #PowerBI 002
  • Learn Basic SQL – 1 Hour Training Course – SQL Training Online
  • Create Table Statement in SQL Server and Inserting Baseball Homerun Leader Dataset – SQL Training Online

Popular Posts

  • SQL Functions
  • SQL Jobs in Oracle and Microsoft SQL Server
  • Troubleshooting a SQL Join
Copyright © 2023 · SQLTrainingOnline.com · Consulting at EmbarkBlue.com