Is using 1=1 in WHERE wrong?

Asked

Viewed 108 times

1

Is having a certain dispute whether or not the use of 1=1 in the where of a query in my team. Using this method to generate querys dynamically brings some harm in query performance or it does not influence?

  • 5
  • 2

    Perhaps it has already been answered in the question linked by rray. But you could edit the question and put more context, real example of use to see if the question is not duplicate the other.

  • If you use a join to form the conditions with a vector will not be necessary 1=1, for in the join a vector like this [1, 2, 3] would result in this: 1 AND 2 AND 3, of course this is a very simple example.

  • @rray I had already read this post, and it does not answer my question, my question was whether in performance the 1=1 is harmful, and yes I use the 1=1 to facilitate when putting the clauses in progress, so my question ñ was answered

  • 2

    @João It’s not wrong but it’s ugly :-). With two lines more code SQL is sent to the bank only with what really matters. See the comment of Bacco in the answer of the linked question. As for performance, your database responds (analyze the execution plan of the two queries - at least in most banks will be equal).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.