follow this rule when loop and read is coming....
1 table 2table condition.
1 1 loop at 1st table
read for 2nd table..
____________________________________________________________-
1 many loop at for 2nd table..
Read for 1st table....
_______________________________________________________________
many 1 loop at 1st table
Read for 2nd table...
----------------------------------------------------------------------------------------------
many many loop at 1st table
loop at 2nd table....
_________________________________________________
i think this information will be useful.................