Using Search Conditions

Adding a WHERE clause to a SELECT statement retrieves only those records that meet a specific condition. .

Selecting Records That Meet a Specific Condition

Sometimes you will not want to see information on all the employees in the Employees table. To look at employees with the first name, John, you would enter:
SELECT *
FROM Employees
WHERE GivenName = 'John'

EmployeeID

ManagerID

Surname

GivenName

DepartmentID

...

318

1,576

Crow

John

400

...

862

501

Sheffield

John

100

...

1,483

1,293

Letiecq

John

300

...

Apostrophes and Case-Sensitivity

The apostrophes (single quotes) around the name 'John' are required. They indicate that John is a character string. Quotation marks (double quotes) have a different meaning. Quotation marks can be used to make otherwise invalid strings valid for column names and other identifiers.

The sample database is not case sensitive, so you would get the same results whether you searched for ' 'JOHN', 'john', or 'John'.

Again, you can combine what you have learned:

SELECT GivenName, Surname, BirthDateFROM Employees
WHERE GivenName = 'John'
ORDER BY BirthDate

Ordering Clauses

How you order clauses is important. The FROM clause comes first, followed by the WHERE clause, and then the ORDER BY clause. If you type the clauses in a different order, you will get a syntax error.

Splitting Lines

You do not need to split the statement into several lines. You can enter the statement into the SQL Statements window in any format. If you use more than the number of lines that fit on the screen, the text scrolls in the SQL Statements window.