Menu & Search
Why use WHERE 1=1 in SQL Queries

Why use WHERE 1=1 in SQL Queries

A common SQL question is, why does anyone use WHERE 1=1 in their queries? And what does it do?

The condition means WHERE TRUE, so it’s just bringing back the same query result as it would without. Also, there’s no impact on query execution time.

This is really something you’d add into a query for convenience. When adding in conditions to a query that already has WHERE 1=1, all conditions thereafter will contain AND, so it’s easier when commenting out conditions on exploratory queries.

--  and column1='blah'
    and column2='more_blah'
--  and column3 is not null

This is similar to another technique where you’d have commas before column names rather than after. Again, it’s easier for commenting :

--  ,Column2
--  ,Column5

Peronsally I make use of both of the above.

Convenience is everything when working behind a computer. We have to keep exploring new short-keys and any general ways of working to optimize our efficiency. Some things you might not like and won’t adopt… and sometimes GUI is better than CLI… it’s all personal preference in the end really!



  1. Quintin White
    1 year ago

    Great thank you for the tip !

  2. […] time ago I wrote short blog post on why use WHERE 1=1 in SQL. This time it’s why use WHERE 1=2, but really this can be WHERE 1=9 or anything that […]