Page 1 of 1

one=one and 1=1 in SQL SELECT.

Posted: Mon Nov 23, 2015 3:12 pm
by Manohar Pandit
Hi,

I was give thie query:

Code: Select all

select * from emp where 1=1 
and

Code: Select all

select * from emp where one=one 
and the qustion asked was - If we have some details in a DB2 table and we use a query as listed what will be the result?

I replied the answer will be same...but they said I'm wrong. Can someone please help me with the answer.

Re: one=one and 1=1 in SQL SELCT.

Posted: Tue Nov 24, 2015 11:04 am
by durga
This is an intresting question but I think there is no difference between the two SELECT.

Re: one=one and 1=1 in SQL SELECT.

Posted: Wed Nov 25, 2015 3:33 pm
by Anuj Dhawan
The second query will not work. "one" on the left side of the = will be treated as the COLUMN name by the DB2 and it'll fail indicating column not found, as "one" is not a part of the table. You should get SQLCODE=-206, typically. If there is a column named "one" in the table, the question would not make much sense to me.

1=1 will not fail from a technical point of view, however, it has got its own debate of being useful or not but I think talking about that is not needed in the context of this interview question.

Re: one=one and 1=1 in SQL SELECT.

Posted: Wed Nov 25, 2015 6:03 pm
by enrico-sorichetti
too many interview questions force to reword the dog/lawyer joke

What's the difference between a dead dog and a dead interviewer on a road?
The skid marks in front of the dog. ...

:D

Re: one=one and 1=1 in SQL SELECT.

Posted: Wed Nov 25, 2015 6:35 pm
by Anuj Dhawan
enrico-sorichetti wrote:What's the difference between a dead dog and a dead interviewer on a road?
The skid marks in front of the dog. ...

:D
shh..hhh many of us had been interviewers! :rofl:

Re: one=one and 1=1 in SQL SELECT.

Posted: Wed Nov 25, 2015 7:05 pm
by enrico-sorichetti
But probably no one of us asked stupid questions.

Re: one=one and 1=1 in SQL SELECT.

Posted: Thu Dec 10, 2015 12:35 pm
by durga
Anuj Dhawan wrote:The second query will not work. "one" on the left side of the = will be treated as the COLUMN name by the DB2 and it'll fail indicating column not found, as "one" is not a part of the table. You should get SQLCODE=-206, typically. If there is a column named "one" in the table, the question would not make much sense to me.

1=1 will not fail from a technical point of view, however, it has got its own debate of being useful or not but I think talking about that is not needed in the context of this interview question.
Thanks for the answers. After reading about the explanation on "one" makes me feel that why it did not strike me :evil:

Re: one=one and 1=1 in SQL SELECT.

Posted: Thu Dec 10, 2015 12:37 pm
by durga
enrico-sorichetti wrote:too many interview questions force to reword the dog/lawyer joke

What's the difference between a dead dog and a dead interviewer on a road?
The skid marks in front of the dog. ...

:D
I had the same reactions after coming out of the interview... :rofl:

Re: one=one and 1=1 in SQL SELECT.

Posted: Fri Dec 18, 2015 4:34 pm
by Manohar Pandit
Thanks for the answers. It was really a tricky one!