Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to display always just the first value from the same values in a result table of an SQL query?

I have a select query, which returns many same ordered values in one column.

Looks like this:

Id Type
1 A
2 A
3 A
4 B
5 B
6 C
7 C
8 C

But I like to display like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Id Type
1 A
2
3
4 B
5
6 C
7
8

Thanks for any advice!

>Solution :

You can use lag window function,

select t.id, 
    case when lag([type]) over(order by id)=[type] then '' else [type] end [Type]
from t
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading