RSS

Monthly Archives: October 2022

SQL Server query same values First value from the result show in first row | Only first row from a specific Column with same value


Example : If you want to show the result like that , If you use master detail table like Loan & loan payment return partially against same lone then you want to show details Loan amount & partially received amount then this is usefull for you.

IDFlagAmount
1A200
2A200
3A200
4B100
5B100
6C300
7C300
8C300

But I like to display like this:

IDFlagamount
1A200
20
30
4B100
50
6C300
7300

Solution ::

You can use lag window function,

select t.ID, 
    case when lag([Flag]) over(order by ID)=[Flag] then '' else [Flag] end [Results]
from t

Search result :: sql server same value show first row only | Duplicate Column value show One Time at top

 
Leave a comment

Posted by on October 17, 2022 in SQL Query