What does '' = '' mean

select * from Employees where Name = 'John' or ''=''

      

This statement retrieves all employees in the table.

I couldn't figure out how is it interpreted ''=''

? Could you please explain?

+3


source to share


2 answers


''=''

always true

as it compares two empty strings

So essentially ''=''

is Tautology

, and in addition, you are using a condition OR

, and thus your entire condition is always true

. Yours WHERE

can also be written as



where Name = 'John' or 1 = 1

      

Your request can only be select * from Employees

because the condition WHERE

has no effect.

+7


source


This is a rather pointless suggestion where

when looking up a name with

where Name = 'John'

      

But it also searches with an expression that always returns true:

or '' = ''

      

This way, all data will be returned independently.



There should be no reason to include the second part unless the clause where

is generated on the fly somewhere and the name filter is optional. If you include the always true part, it will prevent an error if the names are not filtered. I would also question its use, as it will return additional data.

If this is a generated sentence where

and it is needed, it might make more sense:

or 1=2

      

Then you won't be returning any additional data.

+1


source







All Articles