Back to articles list
- 1 minutes read

How to Define the Order of Items in a Database

What do you do if your data needs to have a defined order? The database itself does not guarantee the order of records unless you explicitly use an ORDER BY clause.

However, you can always use a numeric field to define the order in which the items should be displayed. To avoid duplicate positions, use a UNIQUE constraint on that field.

In the example below, the database stores music albums. Each song on an album has its position that can be set in the seq field of the album_song table.

What do you do if your data needs to have a defined order?

Note that the unique constraint is more complicated here. It needs to be applied within each album and not on the seq column itself.

go to top

Our website uses cookies. By using this website, you agree to their use in accordance with the browser settings. You can modify your browser settings on your own. For more information see our Privacy Policy.