<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smart Pandian &#187; where 1=2</title>
	<atom:link href="http://smartpandian.com/tag/where-12/feed/" rel="self" type="application/rss+xml" />
	<link>http://smartpandian.com</link>
	<description>as simple as that...</description>
	<lastBuildDate>Thu, 24 Jun 2010 15:17:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Where 1=1</title>
		<link>http://smartpandian.com/where-11/</link>
		<comments>http://smartpandian.com/where-11/#comments</comments>
		<pubDate>Fri, 08 May 2009 05:41:58 +0000</pubDate>
		<dc:creator>Pandian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[lazy programmer]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[where 1=1]]></category>
		<category><![CDATA[where 1=2]]></category>

		<guid isPermaLink="false">http://smartpandian.com/?p=292</guid>
		<description><![CDATA[There were better ways to do the same


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;style=normal&amp;service=bit.ly&amp;hashtags=lazy+programmer,sql,where+1%3D1,where+1%3D2" height="61" width="50" /><br />
			</a>
		</div>
<p>Its everywhere 1 is equal to 1, unless one does a incorrect math.  You may wonder &#8220;why would one write an extra condition in a SQL which doesn&#8217;t make any difference, and that adds burden to oneself and to others with wierd extra condition?&#8221;</p>
<p>Consider the following SQL,</p>
<pre class="brush: sql;">select * from dept where 1=1 and id = 5000;</pre>
<p>This sql query is, of course same as</p>
<pre class="brush: sql;">select * from dept where id = 5000;</pre>
<p>Basically, this condition &#8220;1=1&#8243; is used by lazy programmers, who wants to create an sql on the fly,i.e, dynamically through scripting, For example, Consider the below vb script.</p>
<pre class="brush: vb;">
strSqlStatement =  &quot;Select * from Debt where 1=1&quot;
For Each Obj in Conditions
strSqlStatement = strSqlStatement &amp; &quot; and &quot; &amp; Obj
Next
</pre>
<p>This is a lazy approach, as programmer could have identified the first condition and prefixed it  with &#8220;where&#8221; , instead of adding &#8220;and&#8221; to every conditions, i.e. as following script.</p>
<pre class="brush: vb;">
strSqlStatement =  &quot;Select * from Debt &quot;
i = 0
For Each Obj in Conditions
If i  = 0  then
strSqlStatement = strSqlStatement &amp; &quot; where &quot; &amp; Obj
Else
strSqlStatement = strSqlStatement &amp; &quot; and &quot; &amp; Obj
End If
i = i + 1
Next
</pre>
<p>Similar to &#8220;where 1=1&#8243;, there is another lazy programmer approach, its &#8220;where 1=2&#8243;. The purpose of &#8220;where 1=2&#8243; is to extract the list of column names in a table, and dynamically create &#8220;CREATE &#8221; or &#8220;INSERT &#8221; sql statements without fetching a record. Similar to the previous, There were better ways to do the same.</p>
<p>Ref:<br />
* <a href="http://www.novicksoftware.com/TipsAndTricks/tip-sql-server-where-1-equals-2.htm"><em>http://www.novicksoftware.com/TipsAndTricks/tip-sql-server-where-1-equals-2.htm</em></a><br />
* <a href="http://stackoverflow.com/questions/242822/why-would-someone-use-where-11-and-conditions-in-a-sql-clause"><cite>http://stackoverflow.com/questions/242822/why-would-someone-use-<strong>where-11</strong>-and-conditions-in-a-<strong>sql</strong>-clause</cite></a>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1038786113812434";
/* 468x15, created 9/27/08 */
google_ad_slot = "1338610477";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>




	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;title=Where%201%3D1&amp;bodytext=There%20were%20better%20ways%20to%20do%20the%20same" title="Digg"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;title=Where%201%3D1&amp;notes=There%20were%20better%20ways%20to%20do%20the%20same" title="del.icio.us"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;t=Where%201%3D1" title="Facebook"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;t=Where%201%3D1" title="MySpace"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;title=Where%201%3D1" title="StumbleUpon"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F" title="Technorati"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Where%201%3D1&amp;url=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F" title="Slashdot"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;t=Where%201%3D1&opener=bm&amp;ei=UTF-8&amp;d=There%20were%20better%20ways%20to%20do%20the%20same" title="Yahoo! Bookmarks"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fsmartpandian.com%2Fwhere-11%2F&amp;submitHeadline=Where%201%3D1&amp;submitSummary=There%20were%20better%20ways%20to%20do%20the%20same&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://smartpandian.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>


<br/><br/>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://smartpandian.com/where-11/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
