SQL Primer: Using Where . . . In


This example shows use of the WHERE . . . IN clause to return only the records from the Products2 table belonging to a given set of product types. Click on any of the following, and see the result set and SQL source below.

Camping   |   Climbing   |   Clothing

ProductType ProductCode ProductName UnitPrice
Backpack Camping Aces $ 325
Backpack Camping Conestoga $ 175
Backpack Camping Pacific $ 151
Backpack Camping University $ 140
SleepingBag Camping Big Sur $ 200
SleepingBag Camping Cascade $ 210
SleepingBag Camping North Face Sunspot $ 390
SleepingBag Camping Polar Star $ 310
Supplies Camping Daytrip First Aid Kit $ 31
Supplies Camping Scoutpride $ 44.75
Supplies Camping Surelite $ 4
Supplies Camping Wolfgang $ 59
Tent Camping Aptos $ 335
Tent Camping Galaxy $ 535
Tent Camping Scirocco $ 190
Tent Camping Starlight $ 425

The SQL Source of the Recordset is as follows:

SELECT DISTINCT ProductType, ProductCode, ProductName, UnitPrice FROM Products2 WHERE ProductType IN ('Backpack','SleepingBag','Supplies','Tent') ORDER BY ProductType, ProductCode

Go Top   |   Return to DB101 ADO Samples