IT Training

Welcome to Lesson 2 of the TSQL Tutorial. In this lesson we will cover where clauses. I hope you enjoy the lesson.

Select Statements

WHERE

The WHERE command is used to specify a selection criteria.

Usage:

SELECT column(s)
FROM table
WHERE criteria
Example: We want to select only those employees that live in the city London
         (Note: we use single quotes around 'London' because it is a text field.
          Text fields will be highlighted in red for readability.)
SELECT *
FROM employees
WHERE city = 'London'
Results:

EmployeeID

LastName

FirstName

Title

BirthDate

HireDate

Address

City

5

Buchanan

Steven

Sales Manager

3/4/1955

10/17/1993

14 Garrett Hill

London

6

Suyama

Michael

Sales Representative

7/2/1963

10/17/1993

123 Miner Rd.

London

7

King

Robert

Sales Representative

5/29/1960

1/2/1994

Edgeham Hollow

London

9

Dodsworth

Anne

Sales Representative

1/27/1966

11/15/1994

7 Houndstooth Rd.

London

 
Example2:Suppose we want employees that live in London and also has manager in their
         title. 
         (Note that operator commands such as "AND" and "LIKE" are shown in gray.)
         (Note: % is a wildcard character, we want any title that has the word manager)
SELECT *
FROM Employees
WHERE (City = 'London') AND (Title LIKE '%Manager%')

 

Results:

EmployeeID

LastName

FirstName

Title

BirthDate

HireDate

Address

City

5

Buchanan

Steven

Sales Manager

3/4/1955

10/17/1993

14 Garrett Hill

London