从SQL中的表检索重复的数据 [英] retreiving the repeated data from a table in SQL

查看:67
本文介绍了从SQL中的表检索重复的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是我的桌子:
表A:

项目ID描述供应商

1456 IC 74 HC100 X
3459 IC 74 LS221 B
1456 IC 74 LS166 Y
3769 IC 74 LS139 F
6464 IC 74 LS367 G
1456 IC 74 S 74 L
.
.
..继续

在这里,我需要检查ItemID 1456,其中有1个以上的供应商X,Y,L
从表A使用SQL查询.
这样,我需要从具有超过1个供应商的表A中查找所有ItemID?

请帮助..

Hi all,

This is my table:
Table A:

ItemID Description Supplier

1456 IC 74 HC100 X
3459 IC 74 LS221 B
1456 IC 74 LS166 Y
3769 IC 74 LS139 F
6464 IC 74 LS367 G
1456 IC 74 S 74 L
.
.
..going on

Here I need to reteive the ItemID 1456 which has more than 1 suppliers X,Y,L
from the TABLE A using SQL query.
Like this i need to find all the ItemIDs from the TABLE A which has more than 1 suppliers?

Kindly help..

推荐答案

Select ItemID,Count(ItemID)  FROM TableA group by ItemID Having Count(ItemID)>1




Hi,

SELECT 
	TableA_1.ItemId 
FROM
	dbo.TableA TableA_1
	INNER JOIN dbo.TableA TableA_2 ON
		TableA_1.ItemId = TableA_2.ItemId
		AND TableA_1.SupplierId <> TableA_2.SupplierID 

--This should only give you the duplicated ItemId with different SupplierId, if you only want the duplicated ItemId, remove the last condition.



希望对您有所帮助.



Hope it helps.


这篇关于从SQL中的表检索重复的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆