VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 867|回复: 1

关于多表连接查询消除重复行的问题

[复制链接]

1

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2021-3-12 10:00:01 | 显示全部楼层 |阅读模式
我有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

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

使用道具 举报

0

主题

16

帖子

10.00

积分

新手上路

Rank: 1

积分
10.00
发表于 2021-3-12 14:45:01 | 显示全部楼层
最有可能的原因是Sunyes_ProductCatalog中的str_Product_CatalogCode不能唯一标识一笔记录,有重复的;或者是Sunyes_ProductBrandCatalog中的str_Product_BrandCode有重复的。
怎么改这个问题要看你SELECT中的所有字段分别取自三个表中的哪个表。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表