SELECT *
FROM a_really_big_table
WHERE EXISTS (SELECT day_of_week FROM sys_calendar.calendar WHERE day_of_week = 2 -- is it a Monday AND calendar_date = date -- check todays date )
;
Teradata will immiediately determine whether the subquery returns an empty result set, and if so, will not even attempt to execute the outer query.
You can use the EXISTS clause as follows:
SELECT *
FROM a_really_big_table
WHERE EXISTS
(SELECT day_of_week
FROM sys_calendar.calendar
WHERE day_of_week = 2 -- is it a Monday
AND calendar_date = date -- check todays date
)
;
Teradata will immiediately determine whether the subquery returns an empty result set, and if so, will not even attempt to execute the outer query.