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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.