Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a default ORDER BY value?

Tags:

mysql

I have a dynamic mysql query, and the ORDER BY part is hard-coded into the query.

Problem is, I don't know if every query will have an ORDER BY, nor do I know which columns will be available to order by.

Is there a default value I can write, so that I can use

if (empty($order)){$order = "default_value"}

$query = "select ...... ORDER BY $order"
like image 412
d-_-b Avatar asked Sep 16 '26 22:09

d-_-b


1 Answers

There is no default order to results from queries. If you don't explicitly specify an ORDER BY clause, the data order is undefined. You can only specify ASC DESC and some columns.

like image 159
Oleksi Avatar answered Sep 18 '26 12:09

Oleksi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!