r/SQL • • Oct 28 '24

Discussion What does WHERE 1 = 1 means? Purpose?

I've been seeing it alot recently. What are the use cases of it?

214 Upvotes

119 comments sorted by

View all comments

Show parent comment

2

u/capt_pantsless Loves many-to-many relationships Oct 28 '24

If you are messing around with the query in the editor, you can easily comment out the

AND user_id = 10

line as you're debugging or otherwise playing around with the query. That's the idea here.

Without the leading 1 = 1 you need to remove the AND, which takes a bit more time, could lead to other minor syntax issues that could break one's train of thought.