Possible Duplicate:
Why do results from a SQL query not come back in the order I expect?
From reading 7.5 Sorting Rows and from issues I've seen with PostgreSQL, my impression is the following, but that section is not fully explicit, so I would be grateful if someone could verify:
SELECT * FROM items;
has no guaranteed order.
SELECT * FROM items ORDER BY published_date ASC;
guarantees that two items with different dates come in a given order, but does not guarantee that two items with the same date always come in the same order.
SELECT * FROM items ORDER BY published_date ASC, id ASC;
always returns items in the same order, since it is fully deterministic.
Do I have this right?
I'm not quite clear about whether sorting on one attribute (such as published_date
) guarantees the order for records with the same value, as in the second example.