J
Jennifer Cali
Hi - I have a strange one! My query below isn't working correctly. I have a
main events table and the event number is joined to one of three other
subtables (table AV, tblScenic, and tblLighting). The query does run, but if
I have more than one entry for an event in a given table, it is multiplying
the end result by 6, 8, etc. (it appears to be random).
For example, tblScenic has two entries tied to event number 4:
Palm Trees $300
Music $120
The footer holds the total of $420.
I then created the SQL below to pull values from these tables based on the
event number and sum the values so that I could see, by event, the total
costs for AV, Scenic, and Lighting. The problem is that the SUM is only
correct if there is ONE value in the Scenic table...when I have more than one
(like in the above example) it is multiplying it by 8 (for some reason!)
because the result of the query showing the total cost of Scenic items for
event number four comes out as $3360 instead of $420. Any help would be
greatly appreciated - I have no idea what's wrong with my SQL. You'll see two
different queries below...both yield the same result.
OPTION #1:
SELECT
tblEventSetup.atnEventSetup,
Sum(tblAV.curAVEstimateBudget) AS [Sum Of curAVEstimateBudget],
Sum(tblAV.curAVActualCost) AS [Sum Of curAVActualCost],
Sum(tblScenic.curScenicEstimateBudget) AS [Sum Of curScenicEstimateBudget],
Sum(tblScenic.curScenicActualCost) AS [Sum Of curScenicActualCost],
Sum(tblLighting.curLightEstimateBudget) AS [Sum Of curLightEstimateBudget],
Sum(tblLighting.curLightActualCost) AS [Sum Of curLightActualCost]
FROM tblEventSetup, tblAV, tblLighting, tblScenic
where tblEventSetup.atnEventSetup = tblAV.ingzEventAV and
tblEventSetup.atnEventSetup = tblLighting.ingzEventLight and
tblEventSetup.atnEventSetup = tblScenic.ingzEventScenic
GROUP BY tblEventSetup.atnEventSetup;
OPTION #2:
SELECT DISTINCTROW tblEventSetup.atnEventSetup,
Sum(tblAV.curAVEstimateBudget) AS [Sum Of curAVEstimateBudget],
Sum(tblAV.curAVActualCost) AS [Sum Of curAVActualCost],
Sum(tblScenic.curScenicEstimateBudget) AS [Sum Of curScenicEstimateBudget],
Sum(tblScenic.curScenicActualCost) AS [Sum Of curScenicActualCost],
Sum(tblLighting.curLightEstimateBudget) AS [Sum Of curLightEstimateBudget],
Sum(tblLighting.curLightActualCost) AS [Sum Of curLightActualCost]
FROM ((tblEventSetup INNER JOIN tblAV ON tblEventSetup.atnEventSetup =
tblAV.ingzEventAV) INNER JOIN tblLighting ON tblEventSetup.atnEventSetup =
tblLighting.ingzEventLight) INNER JOIN tblScenic ON
tblEventSetup.atnEventSetup = tblScenic.ingzEventScenic
GROUP BY tblEventSetup.atnEventSetup;
main events table and the event number is joined to one of three other
subtables (table AV, tblScenic, and tblLighting). The query does run, but if
I have more than one entry for an event in a given table, it is multiplying
the end result by 6, 8, etc. (it appears to be random).
For example, tblScenic has two entries tied to event number 4:
Palm Trees $300
Music $120
The footer holds the total of $420.
I then created the SQL below to pull values from these tables based on the
event number and sum the values so that I could see, by event, the total
costs for AV, Scenic, and Lighting. The problem is that the SUM is only
correct if there is ONE value in the Scenic table...when I have more than one
(like in the above example) it is multiplying it by 8 (for some reason!)
because the result of the query showing the total cost of Scenic items for
event number four comes out as $3360 instead of $420. Any help would be
greatly appreciated - I have no idea what's wrong with my SQL. You'll see two
different queries below...both yield the same result.
OPTION #1:
SELECT
tblEventSetup.atnEventSetup,
Sum(tblAV.curAVEstimateBudget) AS [Sum Of curAVEstimateBudget],
Sum(tblAV.curAVActualCost) AS [Sum Of curAVActualCost],
Sum(tblScenic.curScenicEstimateBudget) AS [Sum Of curScenicEstimateBudget],
Sum(tblScenic.curScenicActualCost) AS [Sum Of curScenicActualCost],
Sum(tblLighting.curLightEstimateBudget) AS [Sum Of curLightEstimateBudget],
Sum(tblLighting.curLightActualCost) AS [Sum Of curLightActualCost]
FROM tblEventSetup, tblAV, tblLighting, tblScenic
where tblEventSetup.atnEventSetup = tblAV.ingzEventAV and
tblEventSetup.atnEventSetup = tblLighting.ingzEventLight and
tblEventSetup.atnEventSetup = tblScenic.ingzEventScenic
GROUP BY tblEventSetup.atnEventSetup;
OPTION #2:
SELECT DISTINCTROW tblEventSetup.atnEventSetup,
Sum(tblAV.curAVEstimateBudget) AS [Sum Of curAVEstimateBudget],
Sum(tblAV.curAVActualCost) AS [Sum Of curAVActualCost],
Sum(tblScenic.curScenicEstimateBudget) AS [Sum Of curScenicEstimateBudget],
Sum(tblScenic.curScenicActualCost) AS [Sum Of curScenicActualCost],
Sum(tblLighting.curLightEstimateBudget) AS [Sum Of curLightEstimateBudget],
Sum(tblLighting.curLightActualCost) AS [Sum Of curLightActualCost]
FROM ((tblEventSetup INNER JOIN tblAV ON tblEventSetup.atnEventSetup =
tblAV.ingzEventAV) INNER JOIN tblLighting ON tblEventSetup.atnEventSetup =
tblLighting.ingzEventLight) INNER JOIN tblScenic ON
tblEventSetup.atnEventSetup = tblScenic.ingzEventScenic
GROUP BY tblEventSetup.atnEventSetup;