1

I am trying to select from a table that contains some duplicate rows like the one below:

OS Value
A 5
A 10
B 5
B 10

I am trying to remove duplicates from both columns to get only unique values. It doesn´t matter which value will be at which OS. It should get something like this:

OS Value
A 5
B 10

Thank you!

3 Answers3

0

create table DemoTable (os char(1), value smallint)
insert into demotable values ('A', 5), ('A', 10), ('B', 5), ('B', 10)
declare @i int =1
DECLARE @tempTable table (rowid int, os char(1), value smallint)

while @i<3 --this can be replaced with maximum
begin
insert into @tempTable (rowid, os, value)
values (@i, (select OS from (SELECT ROW_NUMBER() over(order by os) rowid,OS FROM DemoTable GROUP BY OS) x where rowid = @i), (select value from (SELECT ROW_NUMBER() over(order by value) rowid, value FROM DemoTable GROUP BY value) x where rowid = @i))

set @i = @i + 1
end

select os, value from @tempTable

Masood
  • 1
0

I am try solve this question, Please check my answer

SELECT * from test  group by os_1 ;

enter image description here

I just changed column name and table name ,you can change to your column and table name .

Ganesan J
  • 539
  • 7
  • 12
-1

You can group by the first column and get the max value of the second:

SELECT OS, MAX(Value)
FROM oss 
GROUP BY OS

Check this DB fiddle.

Joaquín L. Robles
  • 6,261
  • 10
  • 66
  • 96