SELECT pt.entry_id, pt.entry_subject, et.entry_text, pt.when_posted AS time, u.username AS owner_name, decode(pt.tag_1, NULL, '', ''||pt.tag_1||'') || decode(pt.tag_2, NULL, '', ''||pt.tag_2||'') || decode(pt.tag_3, NULL, '', ''||pt.tag_3||'') || decode(pt.tag_4, NULL, '', ''||pt.tag_4||'') || decode(pt.tag_5, NULL, '', ''||pt.tag_5||'') || decode(pt.tag_6, NULL, '', ''||pt.tag_6||'') AS tags FROM (SELECT entry_id, entry_subject, when_posted, MAX (DECODE (seq, 1, tag_desc, NULL)) tag_1, MAX (DECODE (seq, 2, tag_desc, NULL)) tag_2, MAX (DECODE (seq, 3, tag_desc, NULL)) tag_3, MAX (DECODE (seq, 4, tag_desc, NULL)) tag_4, MAX (DECODE (seq, 5, tag_desc, NULL)) tag_5, MAX (DECODE (seq, 6, tag_desc, NULL)) tag_6 FROM (SELECT e.entry_id, d.tag_desc, entry_subject, when_posted, ROW_NUMBER () OVER (PARTITION BY e.entry_id ORDER BY d.tag_desc ASC NULLS LAST) seq FROM (SELECT * FROM (SELECT a.*, ROWNUM rn FROM ( SELECT * FROM phpbb_weblog_entries e, phpbb_users u WHERE u.user_weblog = e.weblog_id AND u.user_id = :OWNER_ID AND e.entry_access <= 1 ORDER BY when_posted DESC) a WHERE ROWNUM <= 5) WHERE rn >= 1) e, tsn_tags_links l, tsn_tags_desc d WHERE e.entry_id = l.entry_id(+) AND l.tag_id = d.tag_id(+)) WHERE seq <= 6 GROUP BY entry_id, entry_subject, when_posted) pt, phpbb_weblog_entries et, phpbb_users u WHERE pt.entry_id = et.entry_id AND u.user_weblog = et.weblog_id ORDER BY et.when_posted DESC NULLS LAST