View previous topic :: View next topic
|
Author |
Message |
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi All,
In some of the SQLs i saw below predicate clause
Whats is the use of this condition? Is any advantage or disadvantage for this?? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest for more useful replies, it will help if you post the complete query |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi Dick,
My query is like below,
Code: |
DELETE FROM tab1 WHERE 1=1 |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi Terry,
Then what is the difference betwen below two codes?
Code: |
DELETE FROM tab1 WHERE 1=1 |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
They should both delete all of the rows. |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
I know that they both will delete all the rows.But what is the difference coming there? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|