foreach row (id,hid,instance,etc...) in table1 lookup row in table2 that contains id,hid lookup a row in table3 that contains id,hid,instance