iiddaannyy

sql

Feb 5th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.29 KB | None | 0 0
  1. SELECT `threads`.`id`, `threads`.`name`, COALESCE(`posts`.`date`, `threads`.`date`) AS `date`
  2. FROM `threads`
  3. LEFT JOIN (
  4.     SELECT `posts`.`tothread`, `posts`.`date`
  5.     FROM `posts`
  6.     ORDER BY `date` DESC
  7. ) AS `posts`
  8.     ON `posts`.`tothread` = `threads`.`id`
  9. GROUP BY `name`
  10. ORDER BY `date` DESC
Advertisement
Add Comment
Please, Sign In to add comment