Say you have this query:
SELECT a, b, c
FROM mytable
WHERE d=1 AND e=2If you want to change fields in SELECT or WHERE, you'll need to rewrite your query by adding or removing it's parts. Source control diff would also show a whole line change.
But if you write it like this:
SELECT 1
, a
, b
, c
FROM mytable
WHERE 1=1
AND d=1
AND e=2You can comment out any field or condition simply by adding --:
SELECT 1
--, a
, b
, c
FROM mytable
WHERE 1=1
--AND d=1
AND e=2when you have a lot of conditions and need to iterate fast, this way of writing queries is much better for debugging and source control since diff is always contianed to the one line you edit.
- Log in to post comments
