We have the need to add a join to a simple table that has a small set of product numbers and their corresponding consolidated product number.
So the order table links to this table, and if a consolidated product number is Not Null, then it will be the GROUP BY, otherwise the regular product number is the GROUP BY.
So the question from an SQL perspective:
Is it more efficient to do a UNION with an INNER JOIN of equality and then inequality....
or to do a LEFT OUTER JOIN and use IIF() to determine which product number to SUM/GROUP BY.
The latter is a bit ugly as one must use the IIF() in the GROUP BY statement.
My gut says the latter will be a bit more efficient, but my thinking has always been that UNION forces a double pass thru the tables....but that's not really true, is it ?
So the order table links to this table, and if a consolidated product number is Not Null, then it will be the GROUP BY, otherwise the regular product number is the GROUP BY.
So the question from an SQL perspective:
Is it more efficient to do a UNION with an INNER JOIN of equality and then inequality....
or to do a LEFT OUTER JOIN and use IIF() to determine which product number to SUM/GROUP BY.
The latter is a bit ugly as one must use the IIF() in the GROUP BY statement.
My gut says the latter will be a bit more efficient, but my thinking has always been that UNION forces a double pass thru the tables....but that's not really true, is it ?