How to remove duplicate lines while keeping other columns

4

In the example below, I'm interested in removing duplicates of the rows in columns title and time without worrying about the other columns.

In the example below I'm interested in having the query return rows 32, 34 and 36 and all columns.

id | title   | time  | domain
32   title1    12:30   domain1.com
33   title1    12:30   domain2.com
34   title2    14:20   domain1.com
35   title2    14:20   domain2.com
36   title3    15:30   domain55.com
    
asked by anonymous 04.11.2016 / 17:26

1 answer

5

User or Group by and min () ,

declare @tabela table
(
   id int,
   title varchar(20),
   time time,
   domain varchar(30)
)

insert into @tabela values

(32, 'title1',    '12:30' ,  'domain65.com'),
(33, 'title1',    '12:30' ,  'domain2.com'),
(34, 'title2',    '14:20' ,  'domain1.com'),
(35, 'title2',    '14:20' ,  'domain2.com'),
(36, 'title3',    '15:30' ,  'domain55.com')

select min(id) as ID, title, time, (select domain from @tabela where id = min(t1.id)) 
from @tabela t1
group by title, time

Or

select min(id) as ID, title, time, min(domain) from @tabela
group by title, time
    
04.11.2016 / 17:38