SQL Server – SELECT statement with WHERE clause

SELECT Statement with WHERE clause

We have already seen how to use simple SELECT statement in my previous post.

In this post we shall see different ways of using WHERE clause with SELECT statement. The WHERE conditions filters the output of the FROM clause and restricts the rows that will be returned in the result set.

SELECT column_list FROM table_name

WHERE condition

The WHERE conditions can make use of several possible comparison operators as listed in table below:

Table: Standard Comparison Operators

Description Operator Example
Equals = Quantity = 12
Greater than > Quantity > 12
Greater than or equal to >= Quantity >= 12
Less than < Quantity < 12
Less than or equal to <= Quantity<= 12
Not equal to <> Quantity <> 12

We shall use AdventureWorks Database in following examples.

USE AdventureWorks

SELECT * FROM Production.Product WHERE ReorderPoint = 750

SELECT * FROM Production.Product WHERE ReorderPoint > 700

SELECT * FROM Production.Product WHERE ReorderPoint >= 750

SELECT * FROM Production.Product WHERE ReorderPoint < 50

SELECT * FROM Production.Product WHERE ReorderPoint <= 60

SELECT * FROM Production.Product WHERE ReorderPoint <> 800

See also:

DML SELECT Statement

SELECT Statement with WHERE BETWEEN clause

SELECT Statement with WHERE IN clause

Good Luck!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: