Difference

The difference between two sets of rows produces a table that contains rows in the first set that are not also in the second set. Use the keywords NOT EXISTS or NOT IN to introduce subqueries that show the difference between two sets. The following figure illustrates the difference set operation.
Figure 1: The difference set operation

This figure is described in the surrounding text.

The following query is an example of a nested SELECT statement that shows the difference between the stock and items tables.
Figure 2: Query
SELECT stock_num, manu_code, unit_price FROM stock
   WHERE stock_num NOT IN
      (SELECT stock_num FROM items)
   ORDER BY stock_num;
The result contains all the elements from only the first set, which returns 17 rows.
Figure 3: Query result
stock_num manu_code unit_price 

      102 PRC          $480.00
      102 SHM          $220.00
      106 PRC           $23.00
      ⋮
      312 HRO           $72.00
      312 SHM           $96.00
      313 ANZ           $60.00
      313 SHM           $72.00