Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12554

Partition and order by in self join table having multiple parents

$
0
0

I come up with this type of table after self Join

BrandIDBrandParentBrandID
1HPNull
8SONY-INK7
3HP-Tonner1
10SONY-Printer7
7SONYNull
2HP-INK1
9SONY-TONER7
4HP-Printer1

But I am Looking for table Like below  I mean first parents record and all their childs in sequence

BrandIDBrandParentBrandID
1HPNull
2HP-INK1
3HP-Tonner1
4HP-Printer1
7SONYNull
8SONY-INK7
9SONY-TONER7
10SONY-Printer7

Could you send me code to get output like second one?


Viewing all articles
Browse latest Browse all 12554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>