This is my table:
I have a problem I don't understand the difference between the following two queries:
Query #1:
SELECT
productID,
SUM(soldQty)
FROM
Sales
WHERE
soldQty <> 0
GROUP BY
ProductID
Query #2:
SELECT
productID,
SUM(soldQty)
FROM
Sales
GROUP BY
ProductID
HAVING
SUM(soldQty) <> 0
Which productID's will result in the queries? Isn't it the same?
The queries are not the same. The first query will
SUMrows where the value ofsoldQtyis not equal to0.The second query, however, will return rows where the
SUMof the values insoldQtydo not total0. As a result if theSUMof the values comes to0, such as10,-4and-6those rows would be omitted. This would not be the case for the first query.Notice that
2is returned in the first dataset, with a value of0forTotalIntColumn, but it is not returned in the second. Neither result set return a row with a value of3forMyColumnasIntColumnonly contains the value0.