I've been working with a SQL query for the last day or so that I can't seem to get working. I'm running an Oracle 8i instance for this query on AIX 4.3.3. I have 3 tables with the following structure:
Table - GM_INV_LOC
SKU_NUM AVAIL_QTY LOC_CD
------------ --------- -------
000018716-04 9 0023
000018716-04 12 0124
Table - GM_SKU
SKU_NUM ITM_CD
------------ ------------
000019986-00 000019986
000019986-01 000019986
Table - GM_SKU2STORE
SKU_NUM MIN_QTY MAX_QTY
------------ ------- -------
000842172-04 1 1
000842172-04 1 1
I'm using the following query:
"select GM_SKU.ITM_CD, GM_SKU.SKU_NUM from GM_SKU
where GM_SKU.SKU_NUM=GM_SKU2STORE.SKU_NUM in
(select GM_SKU2STORE.SKU_NUM from GM_SKU2STORE where sum(MIN_QTY)>0) and GM_SKU.SKU_NUM=GM_INV_LOC.SKU_NUM in
(select GM_INV_LOC.SKU_NUM from GM_INV_LOC where GM_INV_LOC.AVAIL_QTY>1) order by GM_SKU.ITM_CD"
I realize that this is ugly SQL but for some reason, this thing has got me lost. All I want to do is query for the "itm_cd" in the "gm_sku" table and return the item codes for everything that has a "sum(min_qty)>0" from the "gm_sku2store" table and an "avail_qty>0" from the "gm_inv_loc" table. All 3 tables have multiple entries of the same SKU, but each SKU only has 1 "itm_cd". Anyone know what I'm doing wrong here? Probably everything...
Table - GM_INV_LOC
SKU_NUM AVAIL_QTY LOC_CD
------------ --------- -------
000018716-04 9 0023
000018716-04 12 0124
Table - GM_SKU
SKU_NUM ITM_CD
------------ ------------
000019986-00 000019986
000019986-01 000019986
Table - GM_SKU2STORE
SKU_NUM MIN_QTY MAX_QTY
------------ ------- -------
000842172-04 1 1
000842172-04 1 1
I'm using the following query:
"select GM_SKU.ITM_CD, GM_SKU.SKU_NUM from GM_SKU
where GM_SKU.SKU_NUM=GM_SKU2STORE.SKU_NUM in
(select GM_SKU2STORE.SKU_NUM from GM_SKU2STORE where sum(MIN_QTY)>0) and GM_SKU.SKU_NUM=GM_INV_LOC.SKU_NUM in
(select GM_INV_LOC.SKU_NUM from GM_INV_LOC where GM_INV_LOC.AVAIL_QTY>1) order by GM_SKU.ITM_CD"
I realize that this is ugly SQL but for some reason, this thing has got me lost. All I want to do is query for the "itm_cd" in the "gm_sku" table and return the item codes for everything that has a "sum(min_qty)>0" from the "gm_sku2store" table and an "avail_qty>0" from the "gm_inv_loc" table. All 3 tables have multiple entries of the same SKU, but each SKU only has 1 "itm_cd". Anyone know what I'm doing wrong here? Probably everything...