Combining Clauses

Nothing exists in a vacuum, so this section takes you through some composite examples that demonstrate how combinations of clauses perform together.

Example 5.1

Find all the checks written for CASH and GAS in the CHECKS table and order them by REMARKS.

							SELECT PAYEE, REMARKS
							FROM CHECKS
							WHERE PAYEE = 'CASH'
							OR REMARKS LIKE'GA%'
							ORDER BY REMARKS;

PAYEE                REMARKS
==================== ====================

JOANS GAS            GAS
JOANS GAS            GAS
LOCAL UTILITIES      GAS
CASH                 TRIP TO BOSTON
CASH                 TRIP TO DAYTON
CASH                 WILD NIGHT OUT

Note the use of LIKE to find the REMARKS that started with GA. With the use of OR, data was returned if the WHERE clause ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.