I have a field name session_dayofweek in the database which stores day name like for example ‘Mon’. I want to get the records sorted by the session_dayofweek. The records should be sorted like Sun, Mon, Tue etc. starting from sunday. I am running the query on wordpress database.
Here is my query:
$wpdb->pre_assignments = $wpdb->prefix . 'tc_pre_assignments';
$get_session_name=$wpdb->get_results("SELECT $wpdb->pre_assignments.*,$wpdb->sessions.* FROM $wpdb->pre_assignments JOIN $wpdb->sessions on $wpdb->pre_assignments.session_id = $wpdb->sessions.session_id WHERE $wpdb->sessions.session_id='".$session_id."'");
Please help me. Thanks in advance.
you can use a conditional order by
if you are looking for a pattern sort (aka sun, mon, tue, wed, thu, fri, sat, sun, mon, tue.. etc) you could do something like this
sample fiddle