Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Use of predicate clause WHERE 1=1

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Wed Jul 29, 2009 8:52 am    Post subject: Use of predicate clause WHERE 1=1
Reply with quote

Hi All,
In some of the SQLs i saw below predicate clause

Code:
WHERE 1=1


Whats is the use of this condition? Is any advantage or disadvantage for this??
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jul 29, 2009 9:01 am    Post subject:
Reply with quote

Hello,

It is a way to force an equal in a query. . . One will always equal one. . .

I don't know that i'd think in terms of an advantage or a disadvantage.

Suggest you not consider this outside the scope of the query using it.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Wed Jul 29, 2009 9:24 am    Post subject:
Reply with quote

Hi Dick,
I know that 1 is always equal to 1. Then Why we should use this is in a query. I dont think without any valid reason we are using that.

Behind this query there is some reason is there.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jul 29, 2009 9:34 am    Post subject:
Reply with quote

Hello,

Suggest for more useful replies, it will help if you post the complete query icon_wink.gif
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Wed Jul 29, 2009 10:00 am    Post subject:
Reply with quote

Hi Dick,
My query is like below,

Code:
DELETE FROM  tab1 WHERE 1=1
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Jul 30, 2009 7:00 am    Post subject:
Reply with quote

The only reason I can see for including the WHERE predicate in this case would be to remind the next maintainer that a WHERE condition is an option when deleting rows of a table. Kind of like using a place holder. As written, ALL rows will be deleted.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Thu Jul 30, 2009 9:04 am    Post subject:
Reply with quote

Hi Terry,
Then what is the difference betwen below two codes?


Code:
DELETE FROM  tab1 WHERE 1=1



Code:
DELETE FROM  tab1
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Jul 30, 2009 9:37 am    Post subject:
Reply with quote

Hello,

They should both delete all of the rows.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Thu Jul 30, 2009 4:56 pm    Post subject:
Reply with quote

I know that they both will delete all the rows.But what is the difference coming there?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 30, 2009 5:10 pm    Post subject:
Reply with quote

if your where clauses are always satifisfied (where 1 = 1),
that is the same as having no where clause.

terry may be correct in that the original code was written by an expert,
reminding the next pgmr.

but, I imagine it was written by someone who did not understand that
you do not need a where clause.....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm
No new posts when=group clause: question about the... tuxama DFSORT/ICETOOL 2 Thu Mar 26, 2015 12:51 pm
No new posts pic clause on group variable error CuriousMainframer COBOL Programming 6 Mon Jul 14, 2014 6:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us