MySQL query

A

Anonymous

Guest
Assume I have 3 table:
T1:
id1
id2
Name1

T2:
id1
Name2

T3:
id2
Name3

How do I take all name1 that : T1.id1 is in T2 and T1.id2 is not in T3
 
something like:
Code:
select t1.name from t1, t2, t3 where t1.id1 = t2.id1 and t1.id2 != t3.id2
 
I have tried your idea:
Assume the data in each table is:
T1:
id1=1, id2=1, name=a (rec1)
id1=2, id2=2, name=b (rec2)
id1=3, id2=3, name=c (rec3)
id1=4, id2=4, name=d (rec4)

T2:
id1=1, name=asd
id1=3, name=qwe

T3:
id2=2, name=zxc
id2=4, name=none

What I want to take through sql query is:
1. All name from T1 where id1 not in T2 and id2 in T3 so the result must be 2 record rec2 and rec4. Your query does not give that result!
2. More comlicated situation, assume I have change 3 table name sothat they are the same (t1.name=a with t1.id1=1 and t2.name=a with t2.id=5,..) Now I want all id from T1 where T1.name not in T2 and T1.name in T3.
Can anyone help me?
 
Back
Top