Sub-query and outer's
Posted in 1991
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Internationalization & Character Sets
Here is the select I am doing:
SELECT UNIQUE(wo_stat_154.ROWID),
wo_stat_154.proj_nbr,
wo_stat_154.work_order_nbr,
wo_stat_154.craft_cde
FROM wo_stat_154, OUTER wo_mast_eqip_167, wo_mast_150, cr_mast_900
WHERE wo_stat_154.cnt_nbr = "TT-00001" AND
wo_mast_eqip_167.cnt_nbr = wo_stat_154.cnt_nbr AND
wo_mast_eqip_167.proj_nbr = wo_stat_154.proj_nbr AND
wo_mast_eqip_167.work_order_nbr = wo_stat_154.work_order_nbr AND
wo_mast_150.cnt_nbr = wo_stat_154.cnt_nbr AND
wo_mast_150.proj_nbr = wo_stat_154.proj_nbr AND
wo_mast_150.work_order_nbr = wo_stat_154.work_order_nbr AND
cr_mast_900.cnt_nbr = wo_stat_154.cnt_nbr AND
cr_mast_900.proj_nbr = wo_stat_154.proj_nbr AND
cr_mast_900.craft_cde = wo_stat_154.craft_cde AND
88 <= (SELECT wo_estc_151.jtd_exp_st_hrs / wo_estc_151.estc_tot_hrs * 100
FROM wo_estc_151
WHERE wo_estc_151.cnt_nbr = wo_stat_154.cnt_nbr AND
wo_estc_151.proj_nbr = wo_stat_154.proj_nbr AND
wo_estc_151.work_order_nbr = wo_stat_154.work_order_nbr AND
wo_estc_151.craft_cde = wo_stat_154.craft_cde AND
wo_estc_151.estc_tot_hrs <> 0) AND
44 <= (SELECT wo_stat_154.earned_hrs / wo_estc_151.estc_tot_hrs * 100
FROM wo_estc_151
WHERE wo_estc_151.cnt_nbr = wo_stat_154.cnt_nbr AND
wo_estc_151.proj_nbr = wo_stat_154.proj_nbr AND
wo_estc_151.work_order_nbr = wo_stat_154.work_order_nbr AND
wo_estc_151.craft_cde = wo_stat_154.craft_cde AND
wo_estc_151.estc_tot_hrs <> 0) AND
1=1
And it is producing the following output:
rowid proj_nbr work_order_nbr craft_cde
24 T-01 91-000121-000 AW
23 T-01 91-000121-000 CA
22 T-01 91-000121-000 PF
17 T-01 91-000158-000 CA
15 T-01 91-000372-000 CA
14 T-01 91-000372-000 EL
1 T-01 91-000399-000 CA
29 T-01 91-000399-000 EL
18 T-01 91-000443-000 CA
19 T-01 91-000443-000 PF
31 T-01 91-000451-000 PF
13 T-SPD 91-000389-000 EL
12 T-SPD 91-000389-000 ME
11 T-SPD 91-000390-000 EL
10 T-SPD 91-000390-000 ME
9 T-SPD 91-000391-000 EL
8 T-SPD 91-000391-000 ME
Now the problem is that the sub-querries are not filtering out the right values.
What I mean, this is what the output should look like:
rowid proj_nbr work_order_nbr craft_cde
24 T-01 91-000121-000 AW
22 T-01 91-000121-000 PF
This can produced by removing the outer statement from the above query. I know
what you all are saying, maybe the outer is causeing extra records to be read
from that table. Well, if I remove the referenced to the table with the
outer (wo_mast_eqip_167) then I get the same output (2 rows). In fact, if I
remove all tables execpt the main table (wo_stat_154) I still get only two
rows!
Is this a bug in the SQL processor or don't I know how to program?
P.S. This is in both ISQL and 4GL. Version 2, using standard engine.
Thanks for any help!
Gary
--
Gary L. Smith @ UE&C-Catalytic Unit: Homo Sapiens Model 1
Philadelphia, PA U.S.A Version: alpha
--------------------------------------------------------------------------------
REPLY AT: UUCP: ..!uunet!trac2000!gls INTERNET: gls@trac2000.ueci.com