To protect the innocent, and make things less prone to narcoleptic episodes, I had the following scenario:
- An Access Database with Categories and Products.
- The First product listed in a category was a "special" product. Problem: There wasn't any information that would indicate that product was the first one.
Example Data:
category_id | product_id | product_name | ... |
---|---|---|---|
1 | 2 | Red Jumbo Ball | ... |
1 | 1 | Green Jumbo Ball | ... |
1 | 3 | Blue Jumbo Ball | ... |
2 | 4 | Purple People Eater | ... |
2 | 6 | Yellow Submarine | ... |
2 | 5 | White Christmas | ... |
Once imported, I knew the data was at the whim of the database which meant that I needed to "preserve" the order prior to importing the data. I added another column "autonumber" on my products table in Access.
Once imported, I could set the clustered index to the "autoNum" column in SQL and know the sort order was correct! Of course, it never hurts to add an order by to your select statement. There are many factors that can affect sorting, clustered indexes are just one factor.
No comments:
Post a Comment