When I write a query with a sub-query and then click Visualize, some of the columns in the sub-query are duplicated. This causes an error when running the query. I am using v5.5.0.369 (64-bit).
Original SQL:
SELECT rm_TMRDAllProducts.[Request ID],
rm_TMRDAllProducts.[Request Stage],
ProductsComplete.[Last Date],
COUNT (rm_TMRDAllProducts.[Request ID]) AS [Num Products],
ProductsComplete.[Num Complete],
COUNT (rm_TMRDAllProducts.[Request ID])
- ProductsComplete.[Num Complete] AS Diff
FROM (SELECT rm_TMRDAllProducts.[Request ID],
MAX (rm_TMRDAllProducts.[Complete Date]) AS [Last Date],
COUNT (rm_TMRDAllProducts.[Request ID]) AS [Num Complete]
FROM OPTIMA3.hsi.rm_TMRDAllProducts rm_TMRDAllProducts
WHERE ( ( rm_TMRDAllProducts.Stage = 'Complete'
OR rm_TMRDAllProducts.Stage LIKE 'Cancel%')
AND ( rm_TMRDAllProducts.[Request Stage] <> 'Complete'
AND rm_TMRDAllProducts.[Request Stage] NOT LIKE 'Cancel%'))
GROUP BY rm_TMRDAllProducts.[Request ID]) ProductsComplete
LEFT OUTER JOIN OPTIMA3.hsi.rm_TMRDAllProducts rm_TMRDAllProducts
ON (ProductsComplete.[Request ID] = rm_TMRDAllProducts.[Request ID])
WHERE ( rm_TMRDAllProducts.[Request Stage] <> 'Complete'
AND rm_TMRDAllProducts.[Request Stage] NOT LIKE 'Cancel%')
GROUP BY rm_TMRDAllProducts.[Request ID],
rm_TMRDAllProducts.[Request Stage],
ProductsComplete.[Num Complete],
ProductsComplete.[Last Date]
HAVING ( COUNT (rm_TMRDAllProducts.[Request ID])
- ProductsComplete.[Num Complete] =
0)
ORDER BY ProductsComplete.[Last Date] DESC
After clicking Visualize:
SELECT rm_TMRDAllProducts.[Request ID],
rm_TMRDAllProducts.[Request Stage],
ProductsComplete.[Last Date],
COUNT (rm_TMRDAllProducts.[Request ID]) AS [Num Products],
ProductsComplete.[Num Complete],
COUNT (rm_TMRDAllProducts.[Request ID])
- ProductsComplete.[Num Complete] AS Diff
FROM (SELECT rm_TMRDAllProducts.[Request ID],
MAX (rm_TMRDAllProducts.[Complete Date]) AS [Last Date],
COUNT (rm_TMRDAllProducts.[Request ID]) AS [Num Complete],
rm_TMRDAllProducts.[Request ID] AS [Num Complete]
FROM OPTIMA3.hsi.rm_TMRDAllProducts rm_TMRDAllProducts
WHERE ( ( rm_TMRDAllProducts.Stage = 'Complete'
OR rm_TMRDAllProducts.Stage LIKE 'Cancel%')
AND ( rm_TMRDAllProducts.[Request Stage] <> 'Complete'
AND rm_TMRDAllProducts.[Request Stage] NOT LIKE 'Cancel%'))
GROUP BY rm_TMRDAllProducts.[Request ID]) ProductsComplete
LEFT OUTER JOIN OPTIMA3.hsi.rm_TMRDAllProducts rm_TMRDAllProducts
ON (ProductsComplete.[Request ID] = rm_TMRDAllProducts.[Request ID])
WHERE ( rm_TMRDAllProducts.[Request Stage] <> 'Complete'
AND rm_TMRDAllProducts.[Request Stage] NOT LIKE 'Cancel%')
GROUP BY rm_TMRDAllProducts.[Request ID],
rm_TMRDAllProducts.[Request Stage],
ProductsComplete.[Num Complete],
ProductsComplete.[Last Date]
HAVING ( COUNT (rm_TMRDAllProducts.[Request ID])
- ProductsComplete.[Num Complete] =
0)
ORDER BY ProductsComplete.[Last Date] DESC