Database Sorting Structure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Database Sorting Structure

Post by kendall »

Hello,

I have a question that i need some advice on

i have a database which lists a catalog of products. I want to be able to display these products sorting it based on an order of priority.

now i thought of 2 options

1 altering the code (primary key) - i wanted to do this option into a squencial format but i did not want to tamper with it as the data is related its real life inforamtion.

2 creating a sort column in which would create a sequence sort number but what i would run into problems when i have a new product entered and it needs to be more priority than those already there.



[quote]
What methods of sorting do you guys use in a situation like this?
[/quote]

[quote]
what options do i have or what should be my most effecient option?
[/quote]

Kendall
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Definately add a new column. Add an index on that column. Use program logic to shift priorities if you have to insert a new one between existing ones.

The index will ensure that the sort is quickly preformed. If priorities change from time to time, then priority should definately not be the primary key.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Database Sorting Structure

Post by kendall »

Ok...I understand that...now im no sure how to go about formaulating this 'sort' column...ah mean how to i create this data to define whats priority and whats more priority than what was priority? do is use numeric, alpha ar ture or false wat?? is there somewhere i can possible get and example to follow???

Kendall
Post Reply