chrislarkin
Programmer
- Jun 5, 2001
- 31
Is there any way to force the first row retrieved in a subquery to be returned?
I am dealing with a large table and when I use MAX or MIN to limit the subquery to one record, the response is very slow. Is there a way to have the query respond immediately on the first match?
Here's my SQL --
select DBACV_ACTIVITY, DBACV_DESCRIPTION,
DBACV_BEGIN_DATE, DBACV_END_DATE,
c.SHOWEND_DATE_NUMERIC,
DBACV_HIGH_PST_DATE,
PB.DBAJV_BRANCH AS P_BRANCH, PB.DBAJV_OBJ_ID
, (SELECT MIN(DBAMD_CUSTOMER) FROM LAWDBF7.DBARAMD AR WHERE AR.DBAMD_ACTIVITY = ACT.DBACV_ACTIVITY) AS CUSTOMER
FROM LAWDBF7.DBACACV ACT INNER JOIN LAWDBF7.DBACAJV2_1C_PB PB ON ACT.DBACV_OBJ_ID = PB.DBAJV_OBJ_ID
INNER JOIN LAWDBF7.DBACAJV2_1c c ON PB.DBAJV_OBJ_ID = c.DBAJV_OBJ_ID where showend_date_numeric between 20050701 and 20051231
I am dealing with a large table and when I use MAX or MIN to limit the subquery to one record, the response is very slow. Is there a way to have the query respond immediately on the first match?
Here's my SQL --
select DBACV_ACTIVITY, DBACV_DESCRIPTION,
DBACV_BEGIN_DATE, DBACV_END_DATE,
c.SHOWEND_DATE_NUMERIC,
DBACV_HIGH_PST_DATE,
PB.DBAJV_BRANCH AS P_BRANCH, PB.DBAJV_OBJ_ID
, (SELECT MIN(DBAMD_CUSTOMER) FROM LAWDBF7.DBARAMD AR WHERE AR.DBAMD_ACTIVITY = ACT.DBACV_ACTIVITY) AS CUSTOMER
FROM LAWDBF7.DBACACV ACT INNER JOIN LAWDBF7.DBACAJV2_1C_PB PB ON ACT.DBACV_OBJ_ID = PB.DBAJV_OBJ_ID
INNER JOIN LAWDBF7.DBACAJV2_1c c ON PB.DBAJV_OBJ_ID = c.DBAJV_OBJ_ID where showend_date_numeric between 20050701 and 20051231