dawnKo said:
can anyone tell me what is wrong with the codes??
not without seeing your data. infact, i'm not even sure what you mean by "extra rows"
do you mean there are 10 instead of 5? 2 instead of 1? you havent said what youre expecting..
lets assume you only want a single row.. but youre getting more. they might be identical or they might differ on some values
the situation arises when the link condition table1.id = table2.id (or the other one) is satisfied more than once
example:
table 1 contains id "1" just once
table 2 contains it twice
and table 3 contains it three times
lets assume the tables only contain 2 columns, id and another column called VAL that has the table name in and the row number (so table 1 has t11, table 2 has t21 and t22 etc). if we ignore the id columns (theyre all the same, all 1) you'll get six rows out of this:
t11 t21 t31
t11 t22 t31
t11 t21 t32
t11 t22 t32
t11 t21 t33
t11 t22 t33
they all have ID 1, but:
1 row in t1 matches both rows in t2 (both t2 rows have id 1)
then these two rows each match all 3 rows in table 3 so you get a combination of all 3 rows each matching twice the other rows.. i.e. 1x2x3 = 6 rows
the where clause wont necesarily help. suppose we put a where clause on the VAL column:
WHERE val = t11 //6 rows match this
WHERE val = t21 //3 rows match this
WHERE val = t33 //2 rows match this
so im still getting "extra rows"
-> the database esign is broken or you havent specified clearly enough the join conditions/you arent sure what data you want out of the database. if you can be more specific about the contents of t1, t2 and t3 and what youre hoping to get out of them, im sure we can help