Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select prob

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
is given a table where i have described a tree it is much more deep but i took this simple example...
so "Parent" shows that the "ID" is a child to the "ID" branch indicated in the "Parent", "Count" shows how many childs do the branch have.
====================================
id = Parent = Name = Count=
====================================
1 | 0 | B3 | 2 |
2 | 5 | B6 | 0 |
3 | 5 | B8 | 0 |
4 | 5 | B1 | 0 |
5 | 0 | B9 | 3 |
6 | 1 | B2 | 0 |
7 | 9 | B7 | 0 |
8 | 1 | B4 | 0 |
9 | 0 | B5 | 1 |
====================================
I need to make a select that will give me these unswer,
it means it shoul be ordered so that first goes the less parent after it the childs o f these parent sorted by id then goes the second smallest parent also with its childs sorted by id..and so on!
So it shoul look this way ...if we took that table!
====================================
id = Parent = Name = count=
====================================
1 | 0 | B3 | 2 |
6 | 1 | B2 | 0 |
8 | 1 | B4 | 0 |
5 | 0 | B9 | 3 |
2 | 5 | B6 | 0 |
3 | 5 | B8 | 0 |
4 | 5 | B1 | 0 |
9 | 0 | B5 | 1 |
7 | 9 | B7 | 0 |
====================================

Thank you very much, waiting for your answers and help as soon as posible!
 
Is this example showing that we have 3 parents on file? AA 8~)
 
Hello again,

I've written some sql in MS-Access to generate the results you requested:

SELECT ID,
PARENT,
NAME,
COUNT
FROM Table1
ORDER BY
IIF(PARENT='0',ID,PARENT),
PARENT,
ID;

Cheers

AA 8~)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top