请问ORACLE 数据库 多个表查询不同数据怎么查询
请教老师,有表A,表B,表C三张表,其中表A中的数据项A1和表B中的B1数据项,表C中的C1数据项相同,但是表A中的A2数据项和表B中的B2数据项和表C中的C2数据项有的相同,有的不同,怎么把不同的数据查询出来?如下表,需要查询出522和523、524行
表A 表B 表C
A1 A2 B1 B2 C1 C2
521 34 521 34 521 34
522 35 522 36 522 35
523 37 523 37 523 31
524 40 524 41 524 43
答案:select a.a2,b.b2,c.c2 from a,b,c
where a.a1=b.b1 and b.b1 = c.c1
and (a.a2 != b.b2 or a.a2 != c.c2 orb.b2 != c.c2)
其他:select * from A,B,C where A.A1=B.B1 and A.A1=C.C1 and (A.A2<>B.B2 or A.A2<>C.C2 or B.B2<>C.C2); select a.A1 相同列A1项,a.A1 A表中A2,b.B2 B表中B2,c.C2 C表中C2 from A a,B b,C c where a.A1=b.B1 and a.A1=c.C1 and (a.A2<>b.B2 or a.A2<>c.C2 or b.B2<>b.C2) group by a.A1,a.A2,b.B2,c.C2; select * from a,b,c where a.a1=b.b1 and a.a1=c.c1 and a.a1 not in (
select * from a,b,c where a.a1=b.b1 and a.a1=c.c1 and a.a2=b.b2 and a.a2=c.a2);
上一个:oracle数据库,表person,字段ID,name,新建一个字段,将指定的数据插入这个字段中,怎么插不进去啊???
下一个:linux系统怎么知道oracle数据库名称