Matching each row of one table with one row of another table

kuboX

New Member
I 've got a table:\[code\]TABLE_A----------- Sc Cl Pr Br-----------1 1 1 NULL2 1 1 NULL1 2 2 NULL2 2 2 NULL \[/code\](Sc, Cl, Pr) is a candidate keyIn order to assign values to the field Br (take this for granted it cannot change) I insert these rows into a TABLE_B with 3 fields (Br, Cl, Pr) with field Br auto incremented (to make things simpler assume that TABLE_B is empty and TABLE_A contains only the above rows). So i do something like that\[code\]INSERT INTO TABLE_B (Cl, Pr) SELECT Cl, Pr FROM TABLE_A\[/code\]Now I want to assign the auto generated TABLE_B.Br to TABLE_A.Br in such a way that\[code\]TABLE_B.Cl = TABLE_A.Cl AND TABLE_B.Pr = TABLE_A.Pr\[/code\] AND for every two rows of TABLE_A t1, t2 that \[code\]t1.Cl = t2.Cl AND t1.Pr = t2.Pr AND t1.Sc <> t2.Sc => t1.Br <> t2.Br\[/code\]PS 1: I hope this is not too confusing :(PS 2: The only quick and easy solution i 've find is to add a field in TABLE_B (Sc) then a simple join between the tables would do the job. But adding a column is not an option.
 
Top