$announcements = $db->query_read_slave("
SELECT
announcement.announcementid, startdate, title, announcement.views,
user.username, user.userid, user.usertitle, user.customtitle, user.usergroupid,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
" . (($vbulletin->userinfo['userid']) ? ", NOT ISNULL(announcementread.announcementid) AS readannounce" : "") . "
FROM " . TABLE_PREFIX . "announcement AS announcement
" . (($vbulletin->userinfo['userid']) ? "LEFT JOIN " . TABLE_PREFIX . "announcementread AS announcementread ON (announcementread.announcementid = announcement.announcementid AND announcementread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = announcement.userid)
WHERE startdate <= " . TIMENOW . "
AND enddate >= " . TIMENOW . "
AND " . fetch_forum_clause_sql($foruminfo['forumid'], 'forumid') . "
ORDER BY startdate DESC, announcement.announcementid DESC
" . iif($vbulletin->options['oneannounce'], "LIMIT 1"));