I need some help. I've optimized it to the best that I knew how, but
I'm not an SQL genius when it comes to multiple joins and subqueries.
Code:
SELECT
CO.CONF_TRACK_CD AS CONF_TRACK_CD,
CO.COURSE_OFFERING_ID AS COURSE_OFFERING_ID,
CO.END_DATE AS END_DATE,
CO.END_TIME AS END_TIME,
COALESCE(MAX_CAPACITY, 0) AS MAX_SPACE,
COALESCE(MAX_CAPACITY, 0) - COALESCE(REG.NUMREG, 0) AS NUM_LEFT,
CO.OFFERING_NAME AS OFFERING_NAME,
COALESCE(REG_PER.REGISTRATION_ID, 0) AS REGID,
CO.START_DATE AS START_DATE,
CO.START_TIME AS START_TIME
FROM
COURSE_OFFERING CO INNER JOIN
COURSE ON CO.COURSE_ID = COURSE.COURSE_ID INNER JOIN
(SELECT COUNT(REGISTRATION_ID) AS NUMREG, COURSE_OFFERING_ID
FROM REGISTRATION
WHERE DELETED_IND = 'N'
GROUP BY COURSE_OFFERING_ID)REG ON
REG.COURSE_OFFERING_ID = CO.COURSE_OFFERING_ID INNER JOIN
(SELECT REGISTRATION_ID, COURSE_OFFERING_ID, DELETED_IND
FROM REGISTRATION
WHERE PEOPLE_ID = '01_USER' AND DELETED_IND = 'N') REG_PER
ON REG_PER.COURSE_OFFERING_ID = CO.COURSE_OFFERING_ID
WHERE
(CO.EVENT_ID = 199552189) AND
(CO.START_DATE = '04-02-2006') AND
(CO.DELETED_IND = 'N') AND
(CO.CONF_TRACK_CD IS NOT NULL) AND
(CO.CONF_TRACK_CD <> '')
ORDER BY CO.START_TIME
Main problem, the second subquery:
(SELECT REGISTRATION_ID, COURSE_OFFERING_ID, DELETED_IND
FROM REGISTRATION
WHERE PEOPLE_ID = '01_USER' AND DELETED_IND = 'N')
That query is a huge hit in performance, any suggestions?
________________________
ASP.NET 1.1 Developer
VB.NET Developer