2

Suppose, I have a table like this-

Code | something ------------------ C01 abc C02 mnt C03 lkj C01 dhl C04 poi C05 gtr C02 rty C01 asd ------------------- 

Now, I want only those rows from the table, which rows have Code more than once in that column. So, output will be like-

Code | something ------------------ C01 abc C01 dhl C01 asd C02 mnt C02 rty ------------------- 

I'm new with sql server and query things. Please, help me out. Thanks in advance.

4 Answers 4

1
SELECT * FROM Table WHERE code IN ( SELECT Code FROM Table GROUP BY Code HAVING COUNT(*) > 1 ) 
Sign up to request clarification or add additional context in comments.

1 Comment

dont worry you will be improving by time
0
select * from YourTable where Code in ( select Code from YourTable group by Code having count(*) > 1 ) 

Comments

0
;WITH codes AS ( SELECT code FROM dbo.table GROUP BY code HAVING COUNT(*) > 1 ) SELECT code, something FROM dbo.table AS t INNER JOIN codes AS c ON t.code = c.code; 

Comments

0
SELECT T2.* FROM TableName, (SELECT Code from TableName T1 GROUP BY T1.Code HAVING (COUNT(T1.Code) > 1)) T3 WHERE T2.Code = T3.Code 

Comments