SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old March 11th, 2016, 08:10 AM
stsivaraj stsivaraj is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2016
Posts: 1 stsivaraj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 sec
Reputation Power: 0
Parent and child relationship is broken when do the sort based on parent name

Hi All,
I want to sort the name based on 1st level (sort only applicable root id is null or level ==1). If i search based on name the result set is broken the parent and child relationship.
I am using sql server database. Please let me know what are the fesible way to sort based on 1st level. I am having 5Lakh records. Also, I am considering the performance.


ID PARENT ID ROOT ID NAME level
===============================================
1 NULL NULL FIRST 1
2 1 1 SECOND 2
3 2 1 THIRD 3

4 1 1 FORTH 4
5 4 1 FIFTH 5

6 NULL NULL SIXTH 1
7 6 6 SEVENTH 2
8 7 6 EIGTH 2
9 NULL NULL NINTH 1
10 NULL NULL TENTH 1
11 NULL NULL ELEVEN 1
12 11 11 TWELE 2
13 12 11 THIRTEEN 3
14 13 11 FOURTEEN 4

EXPECTED OUTPUT - SORT BY NAME ASC
====================================

ID PARENT ID ROOT ID NAME level
===============================================
11 NULL NULL ELEVEN 1
12 11 11 TWELE 2
13 12 11 THIRTEEN 3
14 13 11 FOURTEEN 4
1 NULL NULL FIRST 1
2 1 1 SECOND 2
3 2 1 THIRD 3
4 1 1 FORTH 4
5 4 1 FIFTH 5
9 NULL NULL NINTH 1
6 NULL NULL SIXTH 1
7 6 6 SEVENTH 2
8 7 6 EIGTH 2
10 NULL NULL TENTH 1

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Parent and child relationship is broken when do the sort based on parent name


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap