Back to Blog

Beginning SQL

SQL Where

Filter data effectively with SQL WHERE clause. Learn comparison operators, combining conditions, and writing efficient queries in SQL Server.

2 min read

Last updated on

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](../../assets/blog/2012/06/SNAGHTML12455244_thumb.png)

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](../../assets/blog/2012/06/SNAGHTML12483938_thumb.png)

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.

About Joey Blue

Joey Blue teaches practical data skills that companies actually use. With 25+ years of experience solving real data problems for Fortune 500 companies, he's helped 152,000+ students learn SQL, Power BI, reporting, and modern analytics—cutting straight to what works.