I have a situation where one table (STD_DEMO) has one record, and another table (STD_PRGMS) has multiple records for that student, each with a unique START_DATE.
I need to return the name of the student, but only if their earlist program start date occurred before 3/14/02.
SELECT A.STD_NUMBER, A.LAST_NAME, A.FIRST_NAME
,(SELECT MIN(CSQ1.START_DATE) FROM STD_PRGMS CSQ1
WHERE CSQ1.ID_STD_DEMO = A.ID_STD_DEMO) AS MIN_START_DATE
FROM STD_DEMO A
GROUP BY A.STD_NUMBER, A.LAST_NAME, A.FIRST_NAME
HAVING MIN_START_DATE <= '2002-03-14 00:00:00.000'
So I am using a correlated subquery in the SELECT clause to determine that minimum date, and then assiging it the column alias of MIN_START_DATE, but I can't use that alias in the HAVING clause (nor in the WHERE clause, I tried).
Any ideas?
TIA
I need to return the name of the student, but only if their earlist program start date occurred before 3/14/02.
SELECT A.STD_NUMBER, A.LAST_NAME, A.FIRST_NAME
,(SELECT MIN(CSQ1.START_DATE) FROM STD_PRGMS CSQ1
WHERE CSQ1.ID_STD_DEMO = A.ID_STD_DEMO) AS MIN_START_DATE
FROM STD_DEMO A
GROUP BY A.STD_NUMBER, A.LAST_NAME, A.FIRST_NAME
HAVING MIN_START_DATE <= '2002-03-14 00:00:00.000'
So I am using a correlated subquery in the SELECT clause to determine that minimum date, and then assiging it the column alias of MIN_START_DATE, but I can't use that alias in the HAVING clause (nor in the WHERE clause, I tried).
Any ideas?
TIA