日期:2014-05-19  浏览次数:20565 次

关于多表连接查询消除重复行的问题
我有3张表,一张产品表,2张不同类型的分类表,一个分类必要,一个非必要,我的   SQL   语句如下:

select   distinct(int_product_id),str_productCatalog_title,
str_product_name,str_brandcatalog_title,str_Product_ProduceArea,
str_Product_Standard,dat_Product_CreateTime,int_Product_IsFocus,
int_Product_IsHot,int_Product_SortID  
FROM   Sunyes_Product   inner   join   Sunyes_ProductCatalog   on  
str_Product_CatalogCode   =   str_ProductCatalog_SelfCode   left   JOIN  
Sunyes_ProductBrandCatalog   ON   str_Product_BrandCode=str_BrandCatalog_SelfCode  

可是查询出来的数据有很多重复的行,这是为什么?
该怎么修改啊?


------解决方案--------------------
最有可能的原因是Sunyes_ProductCatalog中的str_Product_CatalogCode不能唯一标识一笔记录,有重复的;或者是Sunyes_ProductBrandCatalog中的str_Product_BrandCode有重复的。
怎么改这个问题要看你SELECT中的所有字段分别取自三个表中的哪个表。