ProtocolPirate
Programmer
The following query brings up about 45 records:
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
UNION ALL
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
But when I try to use this as a virtual table I end up with many thousands of records instead of fewer GROUP BY records:
SELECT a.Description
FROM (
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
UNION ALL
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
) As a GROUP BY a.Description
ORDER BY a.Description
Why is this bringing in thousands of records when the query above only brings in 45 records?
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
UNION ALL
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
But when I try to use this as a virtual table I end up with many thousands of records instead of fewer GROUP BY records:
SELECT a.Description
FROM (
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
UNION ALL
SELECT d.Date, d.Description, d.CheckNum
FROM Posting_Brea As p
INNER JOIN Daysheet As d ON d.AcntNumber=p.AcntNumber
INNER JOIN Daysheet AS d2 ON d2.RecID=d.PayID AND d2.ChargeNum=p.ChargeNumber
WHERE d.PymtLo>0 AND d.PayID>0 AND d.Description NOT LIKE '%@%' AND PrimIns='ETNA' OR SecIns='ETNA'
) As a GROUP BY a.Description
ORDER BY a.Description
Why is this bringing in thousands of records when the query above only brings in 45 records?