-
-
Save yahyaahrika/f5ac1b54b31f7c365c03c161adebb985 to your computer and use it in GitHub Desktop.
sql server How to skip rows with same column values in SQL Server? group and repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--https://stackoverflow.com/questions/55249646/how-to-skip-rows-with-same-column-values-in-sql-server | |
CREATE TABLE T( | |
Col1 INT, | |
Col2 VARCHAR(45), | |
Col3 VARCHAR(45) | |
); | |
INSERT INTO T VALUES | |
(1, 'Steve', 'Rodgers'), | |
(2, 'Tony', 'Stark' ), | |
(3, 'Steve', 'Jobs'); | |
SELECT * | |
FROM T | |
WHERE 1 = (SELECT COUNT(Col2) | |
FROM T TT | |
-------------------------------- | |
select * from tablename t | |
where not exists ( | |
select 1 from tablename | |
where colb = t.colb and cola <> t.cola | |
) | |
-------------------------------- | |
select min(cola) as col1, colb, min(colc) as colc | |
from t | |
group by colb | |
having count(*) = 1; | |
WHERE T.Col2 = TT.Col2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment