one=one and 1=1 in SQL SELECT.

All sort of Mainframes Interview Questions.
Post Reply
Manohar Pandit
New Member
Posts: 8
Joined: Wed Aug 06, 2014 4:54 pm

one=one and 1=1 in SQL SELECT.

Post 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.
Last edited by Anuj Dhawan on Wed Nov 25, 2015 1:09 pm, edited 1 time in total.
Reason: Typo: SELCT to SELECT.
durga
Registered Member
Posts: 53
Joined: Mon Jul 01, 2013 3:28 pm

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

Post by durga »

This is an intresting question but I think there is no difference between the two SELECT.
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

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

Post 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.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 824
Joined: Wed Sep 11, 2013 3:57 pm

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

Post 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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

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

Post 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:
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 824
Joined: Wed Sep 11, 2013 3:57 pm

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

Post by enrico-sorichetti »

But probably no one of us asked stupid questions.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
durga
Registered Member
Posts: 53
Joined: Mon Jul 01, 2013 3:28 pm

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

Post 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:
durga
Registered Member
Posts: 53
Joined: Mon Jul 01, 2013 3:28 pm

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

Post 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:
Manohar Pandit
New Member
Posts: 8
Joined: Wed Aug 06, 2014 4:54 pm

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

Post by Manohar Pandit »

Thanks for the answers. It was really a tricky one!
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”