SELECT c.*, CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':',, c.alias) ELSE END as slug FROM #__categories as c LEFT JOIN #__categories AS s ON (s.lft <= c.lft AND s.rgt >= c.rgt) OR (s.lft > c.lft AND s.rgt < c.rgt) LEFT JOIN (SELECT as id FROM #__categories AS cat JOIN #__categories AS parent ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = 'com_sl_downloads' AND parent.published != 1 GROUP BY AS badcats ON = WHERE (c.extension='com_sl_downloads' OR c.extension='system') AND c.access IN (1,1) AND c.published = 1 AND AND is null GROUP BY, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time, c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level, c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id, c.path, c.published, c.rgt, c.title, c.modified_user_id ORDER BY c.lft