各位高人请留步,不看白不看哈!:)))(()))
table1
product_no product_id prod_addr
table2
product_id obj_id
table3
connect_id connect_code
table4
phone_no cust_id
table5
cust_id cust_name
条件
where table1.product_id=table2.product_id
table2.obj_id=table3.connect_id
table4.cust_id=table5.cust_id
table4.phone_no=table1.product.no
结果
table1.prod_addr table1.product_no cust_name table3.connect_code
_________________ __________________ ___________ ____________________
我写的语句如下:
select a.prod_addr,a.product_no,c.connect_code,e.cust_name
where
a.product_id=b.product_id
and b.obj_id=c.connect_id
and d.cust_id=e.cust_id
and d.phone_no=a.product_no
from table1 a,table2 b,table3 c,table4 d, table5 e
得到结果出现N条重复的记录
请问我写的这个查询问题在哪?
象是出现笛卡儿乘积现象。
如何改?谢谢了!
急等!
问题点数:100、回复次数:7Top
1 楼Codavid()回复于 2006-03-04 14:23:07 得分 5
一次得不到吧!我想是用几次子查询Top
2 楼wgsasd311(自强不息)回复于 2006-03-04 14:36:59 得分 5
--try
select distinct a.prod_addr,a.product_no,c.connect_code,e.cust_name
from table1 a,table2 b,table3 c,table4 d, table5 e
where
a.product_id=b.product_id
and b.obj_id=c.connect_id
and a.product_no=d.phone_no
and d.cust_id=e.cust_idTop
3 楼liuex1235(盲流)回复于 2006-03-04 14:45:33 得分 0
这个查询用于建视图所用,distinct最后虽然可以得到最后结果,但是耗费的时间实在太长。
1条记录就重复了几十万遍。实在无法想象!
谢谢各位,继续顶!Top
4 楼liuex1235(盲流)回复于 2006-03-04 14:47:49 得分 0
不好意思,纠正一下,from写到后面来了!
我写的语句是这样的!
select distinct a.prod_addr,a.product_no,c.connect_code,e.cust_name
from table1 a,table2 b,table3 c,table4 d, table5 e
where
a.product_id=b.product_id
and b.obj_id=c.connect_id
and a.product_no=d.phone_no
and d.cust_id=e.cust_id
Top
5 楼wgsasd311(自强不息)回复于 2006-03-04 15:17:52 得分 90
--try
select distinct a.prod_addr,a.product_no,
b.connect_code,
c.cust_name
from table1 a,
(select distinct a.product_id,b.connect_code from table2 a inner join table3 b on a.obj_id=b.connect_id ) b,
(select distinct a.phone_no,b.cust_name from table4 a inner join table5 b on a.cust_id=b.cust_id ) c
where
a.product_id=b.product_id
and a.product_no=c.phone_no
Top
6 楼liuex1235(盲流)回复于 2006-03-04 16:01:15 得分 0
ok,我试下看,成功后马上结帖!谢谢Top
7 楼Codavid()回复于 2006-03-04 22:03:45 得分 0
我也是这样想的,但太复杂了,没写出来!哈哈!
可心问一下,inner join和join 有什么区别吗?Top




