sql - Order Query by Parent and Child -


i'm developing query , want order via parent , subparent, have problem. isn't ordering right.

heres query

    classification_list (     select subparent.[id], subparent.[name], subparent.[parentid],             1 levelclassification, subparent.[id] hierarchy,            subparent.[isactive]     {classification} subparent     subparent.[parentid] null     , (@showall = 1 or subparent.isactive = 1)      union      select child.[id], child.[name], child.[parentid],             el.levelclassification+1 , el.hierarchy,  child.[isactive]     {classification} child                  inner join classification_list el on child.[parentid] = el.[id]     child.[parentid] not null     , (@showall = 1 or child.isactive = 1)  ) select * classification_list order 5,4,1 

heres query output:

query output

the correct output is:

teste   filho 1   filho 2 computador   motherboard   grafica       memoria   memoria 

what i'm doing wrong?

please notice ordering 5,4,1 i.e. in case hierarchy, level , classification id. if notice keenly, you'll see in marked records, ordering because of difference in level.

so if wanted them ordered in different manner classification id, should use order 1


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -