Run a SQL query twice. Get different row orders. That's not a bug.

Databases optimize execution based on indexes, data volume, and memory. Those optimizations can change between queries.

If order matters, you need ORDER BY. And here's where SQL beats Python: mixed sort directions in one line.

ORDER BY signup_date DESC, name ASC

In Python, that requires cmp_to_key or multiple sorting passes. SQL handles it cleanly.

https://jamalhansen.com/blog/order-by-sorting-your-results

#SQL #Python #DuckDB #DataScience #Programming

ORDER BY: Sorting Your Results

SQL returns rows in no guaranteed order. Run the same query twice and you might get different results. ORDER BY gives you control, like Python's sorted() with key functions.

Jamal Hansen
@ham_jansen Of course nobody uses Python to query a db. Or do they?
@yiorgos Lol, I've seen it once or twice. Maybe even done it myself 😀