quwerty quwerty - 1 month ago 18
SQL Question

SQL row order in query

If you are given a query is there a way to determine if you can always get a return in a particular order? Like if you had to return by SSN or name or price,can you guarantee a way in MySQL to get a query to return by SSN?

Answer

can you guarantee a way in MySQL to get a query to return by SSN?

...
ORDER BY ssn

That's the only way.

There are many people that try to be clever, and try to get a database engine to return rows in a certain order without specifying an ORDER BY clause, as if that would somehow optimize something. Don't! Just don't! That's just a recipe for disaster.