Sakib Sakib - 6 months ago 47
MySQL Question

SQL order by length for multiple columns

I want to sort by

order by length
in multiple columns. My code is working for one column, but it's not working with multiple columns.

This is working

$query = $wpdb->get_results("SELECT id,demo1,demo2 FROM $table_name ORDER BY LENGTH(demo1) DESC");

It's not working

$query = $wpdb->get_results("SELECT id,demo1,demo2 FROM $table_name ORDER BY LENGTH(demo1),LENGTH(demo2) DESC");

Answer Source
ORDER BY LENGTH(demo1), demo1 DESC,
         LENGTH(demo2), demo2 DESC
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download