Where to put conditionals in ANSI-syntax SQL queries
Posted
by RenderIn
on Stack Overflow
See other posts from Stack Overflow
or by RenderIn
Published on 2010-06-09T19:26:24Z
Indexed on
2010/06/10
2:02 UTC
Read the original article
Hit count: 245
What's the difference between these two queries? I've been resistant to jumping on the ANSI-syntax bandwagon because I have not been able to unravel various syntactical ambiguities.
Is 1) returning the product of the join and only then filtering out those joined records which have weight >= 500? And is 2) filtering out those prior to the join?
Is 2 bad syntax? Why might I use that?
1:
SELECT SOMETHING
FROM FOO
INNER JOIN BAR
ON FOO.NAME = BAR.NAME
WHERE BAR.WEIGHT < 500
2:
SELECT SOMETHING
FROM FOO
INNER JOIN BAR
ON FOO.NAME = BAR.NAME AND BAR.WEIGHT < 500
© Stack Overflow or respective owner