Home > Mobile >  Merge two rows in SQL based on a key
Merge two rows in SQL based on a key

Time:01-07

I have the table as below:

FK | Field1 | Field2 | Feild3
============================
3  | Y    | N        |N
3  | N    | Y        |N

I want the result to be like this. please help:

FK | Field1 | Field2   | Feild3
================================
3  | Y    | Y          | N

CodePudding user response:

select fk, max(field1), max(field2)
from your_table
group by fk

CodePudding user response:

Select fk, Max(field1), max(field2) from table group by fk

In this case you can just use max to return the highest value for each column.

  • Related