code:
-------------------------------------------------
SELECT M_YEAR, COUNT(*)
FROM TABLE_D D
WHERE D.PRODUCT_CD = 'PP'
AND D.LOCATION_CD = 'ZZ'
AND D.GROUP_CD = 'GG'
AND D.A-ID IN
(SELECT DISTINCT C.A_ID
FROM TABLE_C C
WHERE C.PRODUCT_CD = 'PP'
AND C.LOCATION_CD = 'LL'
AND C.GROUP_CD = 'GG'
AND C.A-ID IN
(SELECT DISTINCT B.A_ID
FROM TABLE_B B
WHERE B.PRODUCT_CD = 'PP'
AND B.M_LIT_CD = 'MLIT'
AND B.A_LIT_CD = 'ALIT'
AND B.A-ID IN
(SELECT DISTINCT A.A_ID
FROM TABLE_A A
WHERE A.PRODUCT_CD = 'PP'
AND A.GROUP_CD = 'GG'
AND A.JV_LIT = 'JVLIT'
)))
GROUP BY M_YEAR;
-------------------------------------------------
This code joins 4 tables together to generate counts. The only common key is PRODUCT_CD, yet this is only a partial key in each table -- that's why I'm using the DISTINCT keyword. The goal of generating counts is to have some numbers to compare to when I change the logic from a SELECT to an UPDATE.
My question is relating to updating each table based on the where clause logic.
- Does the order of the tables in the nested subquery matter?
For example, the current SELECT (and future UPDATE) will be on TABLE_D and subqueries on TABLE_C, TABLE_B, and TABLE_A. The next SELECT (and future UPDATE) will be on TABLE_C with subqueries on TABLE_B, TABLE_A, and TABLE_D ... etc.
- Should I combine these into one subquery, rather then to nest them?
I'm wondering if I can do this on PRODUCT_CD even though its only a partial key on each of my four tables.
- When I change the 'one' subquery to the different table names -- does the order matter?
Many questions here for the PROs!
TRMWEB
-------------------------------------------------
SELECT M_YEAR, COUNT(*)
FROM TABLE_D D
WHERE D.PRODUCT_CD = 'PP'
AND D.LOCATION_CD = 'ZZ'
AND D.GROUP_CD = 'GG'
AND D.A-ID IN
(SELECT DISTINCT C.A_ID
FROM TABLE_C C
WHERE C.PRODUCT_CD = 'PP'
AND C.LOCATION_CD = 'LL'
AND C.GROUP_CD = 'GG'
AND C.A-ID IN
(SELECT DISTINCT B.A_ID
FROM TABLE_B B
WHERE B.PRODUCT_CD = 'PP'
AND B.M_LIT_CD = 'MLIT'
AND B.A_LIT_CD = 'ALIT'
AND B.A-ID IN
(SELECT DISTINCT A.A_ID
FROM TABLE_A A
WHERE A.PRODUCT_CD = 'PP'
AND A.GROUP_CD = 'GG'
AND A.JV_LIT = 'JVLIT'
)))
GROUP BY M_YEAR;
-------------------------------------------------
This code joins 4 tables together to generate counts. The only common key is PRODUCT_CD, yet this is only a partial key in each table -- that's why I'm using the DISTINCT keyword. The goal of generating counts is to have some numbers to compare to when I change the logic from a SELECT to an UPDATE.
My question is relating to updating each table based on the where clause logic.
- Does the order of the tables in the nested subquery matter?
For example, the current SELECT (and future UPDATE) will be on TABLE_D and subqueries on TABLE_C, TABLE_B, and TABLE_A. The next SELECT (and future UPDATE) will be on TABLE_C with subqueries on TABLE_B, TABLE_A, and TABLE_D ... etc.
- Should I combine these into one subquery, rather then to nest them?
I'm wondering if I can do this on PRODUCT_CD even though its only a partial key on each of my four tables.
- When I change the 'one' subquery to the different table names -- does the order matter?
Many questions here for the PROs!
TRMWEB