有三个以上的表,如A,B,C里面有不同的字段,但是有一个id三个表可以连接,我这样弄得
select * from A,B,C where A.d=B.id and B.id=C.id and A.id=c.id ................
这样好多重复的记录啊,该咋修改一下呢?
------解决方案--------------------------------------------------------
Select * From A,B,C Where A.d=B.id and B.id=C.id
------解决方案--------------------------------------------------------
加关键字 distinct 消除重复记录
------解决方案--------------------------------------------------------
连接查询,也就像楼上们说的那样了。
如果记录不是你想要的,可能是就不应该有abc这三个表连接查询。
或者嵌套一个查询
select distinct column1,colunm2 from
(
select * from A,B,C where A.id = B.id and B.id = C.id
)
where ....
------解决方案--------------------------------------------------------
select * from A a inner join B b on a.id = b.id inner join C c on b.id =c.id where a.id = c.id
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
倒~~~按照你15楼的需求,应该用 Union 而不是 表连接
Select id, name Form A
Union All
Select id, name Form B
Union All
Select id, name Form C
------解决方案--------------------------------------------------------