I have a table which holds 5 columns. I than wrote a basic sql statment which group all columns (to make sure there are no duplicates records).
select flag, year, month, name, max(description) description
from table1
group by flag, year, month, name
order by year
Sql output result:
flag | year | month | name | description |
---|---|---|---|---|
No | 2017 | 2 | name1 | random description11 |
Yes | 2017 | 2 | name1 | random description112 |
No | 2018 | 7 | name4 | random description44 |
Yes | 2022 | 4 | name8 | random description999 |
No | 2022 | 4 | name8 | random description999 |
Issue: I am getting 5 reocrds, however i want them to combine into 3 records.
1st & 2nd records are the same bc they have the same year, month, & name
; therefor it should be combined into one records and show row with flag
column value is yes
.
3rd record is has only one record so just show that.
4th & 5th records are the same bc they have the same year, month, & name
; therefor it should be combined into one records and show row with flag
column value is yes
.
What i need:
flag | year | month | name | description |
---|---|---|---|---|
Yes | 2017 | 2 | name1 | random description112 |
No | 2018 | 7 | name4 | random description44 |
Yes | 2022 | 4 | name8 | random description999 |