0

I have a query that selects groups and group postings. In the postings table there is a timestamp collumn, and a group_id. I need to select the greatest timestamp in the postings table, associated with the group id.

Here's my query

$query = "
    SELECT groups.group_name, groups.group_info, groups.group_tags, postings.timestamp 
    FROM groups 
    LEFT JOIN postings ON groups.group_id = postings.group_id 
    GROUP BY groups.group_id 
    ORDER BY `postings`.`timestamp` DESC
";
4

1 回答 1

0
$query = "
    SELECT groups.group_name, groups.group_info, groups.group_tags, max(postings.timestamp) 
    FROM groups 
    LEFT JOIN postings ON groups.group_id = postings.group_id 
    GROUP BY groups.group_id 
    ORDER BY `postings`.`timestamp` DESC
";
于 2013-03-31T00:23:40.083 回答