I have a table with id, task_id, created_taskaction (= rec.cr.date).
I would like to get the latest record for e.g. task_id 0001.
In the wordpress framework I tried this:
> $last_task_action2=$wpdb->get_row("SELECT * FROM $wpdb->task_actions
> NATURAL JOIN ( SELECT id_task, MAX(created_taskaction) AS datetime
> FROM $wpdb->task_actions GROUP BY id_task) mostrecent ON
> $wpdb->task_actions.id_task = $wpdb->mostrecent.id_task AND
> $wpdb->task_actions.datetime = $wpdb->mostrecent.datetime");
But it doesn't work. I tried copying from this thread, but it's still confusing: https://stackoverflow.com/questions/612231/how-can-i-select-rows-with-maxcolumn-value-distinct-by-another-column-in-sql
Even these two don't show ANY data...
$last_task_actiond = $wpdb->get_row("SELECT MAX (created_taskaction) AS 'Max' FROM $wpdb->task_actions");
echo $last_task_actiond;
and
$last_task_actiond = $wpdb->get_row("SELECT MAX (created_taskaction) AS 'Max' FROM wp_task_actions");
echo $last_task_actiond;
Nothing shows up...
task_id
or for each one of them? – ypercubeᵀᴹ Nov 6 '15 at 9:43