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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Tree Insertion 1

Status
Not open for further replies.

kentusha

Programmer
May 18, 2005
8
0
0
DE
Hi-ya

Alrighty I have a sql tree structure,

for example:

("1","0","Top"}
("2","1","A"}
("3","1","C"}
("4","1","D"}

and I want to do an insert and retain the sorting eg:

("1","0","Top"}
("2","1","A"}
("3","1","B"}
("4","1","C"}
("5","1","D"}

what is the best way to do this?
 
Things inserted into an SQL table are not sorted in any particular order. By default (i.e. if you don't do anything to change it) records are usually retrieved in the order in which they were input. If you want to GUARANTEE that order then you need to attach some field that is incremented sequentially (like an autonumber field) and then ORDER BY that field when you retrieve records from the table.
 
thanks for the advice but I am not sure how I would implement it.

I am currently inserting them alpha, and they come out alpha. Can I not go and reorder them somehow without reinsterting them all?

How would your idea get implemented?

This is basically the table structure shown in an insert.
INSERT INTO treemenu_swap ( id, prev, title, url, target, attributes, folder_flag) VALUES("1","0","Top","
 
When you insert records into a table the order is whatever order you insert then as.

When you retrieve then you need to specify which order you wish them to be on by using the "ORDER BY" clause of the "SELECT" statement.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top