|
SQL Keywords: AND
|
|
|
The
AND keyword is used to create a logical conjunction. The formula to
follow is:
SELECT WhatColumn(s)
FROM WhatObject
WHERE Condition1 AND Condition2
The WhatColumn(s) is the name of one or more
columns.
|
The WhatObject
is the name of a table or query. Each condition is written as a SQL operation using the
formula:
Column operator Value
In this case, the WHERE operator resembles a conditional statement. The Condition1 is the first that would be
examined. If the first
condition is false, the whole statement is false and there is no
reason to examine the second condition. If the first condition is true,
then the second condition would be examined.
Here is an example:
USE VideoCollection1;
GO
SELECT Title, Director, YearReleased, Rating
FROM Videos
WHERE YearReleased = N'2006' AND Rating = N'PG-13';
GO
To make the statement easy to use and read, you should
include each part of the AND operation in its own parentheses. Here are
examples:
USE VideoCollection1;
GO
SELECT Title, Director, YearReleased, Rating
FROM Videos
WHERE (YearReleased = N'2006') AND (Rating = N'PG-13');
GO
Here is an example that uses a BETWEEN operator:
BETWEEN [Enter a starting year] AND [Enter an ending year]
|