All pastes #90468 Raw Edit

c0m-

public sql v1 · immutable
#90468 ·published 2006-07-17 18:22 UTC
rendered paste body
mysql> select * from groups_announcements;+----------+-----------------+| group_id | announcement_id |+----------+-----------------+|        4 |              12 ||        4 |              13 ||        5 |              14 ||        5 |              15 |+----------+-----------------+4 rows in set (0.00 sec)mysql> select announcement_id, time_posted from announcements;+-----------------+---------------------+| announcement_id | time_posted         |+-----------------+---------------------+|              11 | 2006-06-18 14:22:05 ||              12 | 2006-07-13 10:07:57 ||              13 | 2006-07-13 10:11:04 ||              14 | 2006-07-13 12:19:12 ||              15 | 2006-07-13 12:21:01 |+-----------------+---------------------+5 rows in set (0.00 sec)mysql> select group_id, groups_announcements.announcement_id, time_posted from announcements left join groups_announcements using (announcement_id);+----------+-----------------+---------------------+| group_id | announcement_id | time_posted         |+----------+-----------------+---------------------+|     NULL |            NULL | 2006-06-18 14:22:05 ||        4 |              12 | 2006-07-13 10:07:57 ||        4 |              13 | 2006-07-13 10:11:04 ||        5 |              14 | 2006-07-13 12:19:12 ||        5 |              15 | 2006-07-13 12:21:01 |+----------+-----------------+---------------------+5 rows in set (0.00 sec)select group_id, groups_announcements.announcement_id, time_posted from announcements as A1 left join groups_announcements using (announcement_id) where time_posted = (select max(A2.time_posted) from announcements AS A2 where A1.announcement_id = A2.announcement_id);+----------+-----------------+---------------------+| group_id | announcement_id | time_posted         |+----------+-----------------+---------------------+|     NULL |            NULL | 2006-06-18 14:22:05 ||        4 |              12 | 2006-07-13 10:07:57 ||        4 |              13 | 2006-07-13 10:11:04 ||        5 |              14 | 2006-07-13 12:19:12 ||        5 |              15 | 2006-07-13 12:21:01 |+----------+-----------------+---------------------+5 rows in set (0.00 sec)