Reputation: 71
I've changed the ID field of several rows. Now "SELECT * FROM table" returns me the rows in the original order.
Example:
ID NAME
1 JOSJ
12 Matt
3 Tom
How do I get them to display in the correct order by default? I'm not talking about a simple "ORDER BY", although it's probably as simple. The table needs to be rearranged somehow?
Upvotes: 1
Views: 2145
Reputation: 21773
SQL does not guarantee any default ordering. A conforming SQL implementation could randomly sort all rows before returning them, for example.
Bottom line is, If you want a certain ordering - specify it in the query. That's all you can ask for.
Upvotes: 1
Reputation: 14333
The default order in the table is just that, the default. Your database will not get confused if they are out of order. You could insert them into a new table using an ORDER BY
, but that's a lot more work than just adding an ORDER BY
to your query
SELECT *
FROM table
ORDER BY ID
You can use the command below to change the ordering, but after an INSERT
or DELETE
the ordering will be changed back to the order they were inserted
ALTER TABLE tablename ORDER BY columnname ASC;
Upvotes: 1