Debugging

After syntax errors cleared up
  1. Query runs; results wrong
  2. Join problems
  3. Know data: count, characterize population
Population defined by WHERE clause

People: 10
Adresses for people with addresses: 13
People with adresses: 9
Addresses of all 10 people: 14

Population test:

select count(*) "count",
       count(distinct name_id) "dist"
  from name
 where name_seriesno = name_now(name_id);

    
count dist
----- ----
    6    6
Numbers should match

If they don't, step through the joins:

  1. Add one join at a time
  2. Test population again
  3. Join problem located when numbers don't match

Join problems;

  1. Population loss; "falling through join"

    Ex: From 6 to 5 after adding join

  2. Population gain: "mulplying through a join"

    Ex: 6 and 7: one item counted twice

  3. 5 and 7: both loss and gain

Correction:

  1. Identify row(s) causing problem
  2. Compare to join conditions
  3. Determine cause


Top References