Click here to Skip to main content
15,914,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted

SQL
Select ItemID,Count(ItemID)  FROM TableA group by ItemID Having Count(ItemID)>1
 
Share this answer
 
Hi,

SQL
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900