G
Guest
Simple question, which one of these two select sql would be faster. I don't
have a large database for testing it and seeing a real difference. But
eventually I will have one.
SQL 1 :
SELECT SALESMANS, PRODUCT, SUM(SALES)
FROM SALES
WHERE PRODUCT = "TOYS"
GROUP BY SALESMANS
ORDER BY SALESMANS
SQL 2 :
SELECT SALESMANS, PRODUCT, SUM(SALES)
FROM SALES
GROUP BY SALESMANS
HAVING PRODUCT = "TOYS"
ORDER BY SALESMANS
The one which is in use in the code that I'm optimizing is SQL 2. I know
that SQL 2 is probably not the best for the situation but this is the kind of
job you have to do when taking code from another person. I just wanted to
know if there's a big enough difference between the 2.
Thanks
have a large database for testing it and seeing a real difference. But
eventually I will have one.
SQL 1 :
SELECT SALESMANS, PRODUCT, SUM(SALES)
FROM SALES
WHERE PRODUCT = "TOYS"
GROUP BY SALESMANS
ORDER BY SALESMANS
SQL 2 :
SELECT SALESMANS, PRODUCT, SUM(SALES)
FROM SALES
GROUP BY SALESMANS
HAVING PRODUCT = "TOYS"
ORDER BY SALESMANS
The one which is in use in the code that I'm optimizing is SQL 2. I know
that SQL 2 is probably not the best for the situation but this is the kind of
job you have to do when taking code from another person. I just wanted to
know if there's a big enough difference between the 2.
Thanks