<?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>iWebDevel &#187; SQLite</title>
	<atom:link href="http://iwebdevel.com/category/coding/sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>http://iwebdevel.com</link>
	<description>Tutorials, howtos and step by step instructions to help you make the perfect web 2.0 website.</description>
	<lastBuildDate>Sun, 28 Mar 2010 15:50:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite</title>
		<link>http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/</link>
		<comments>http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 19:46:36 +0000</pubDate>
		<dc:creator>Dragos</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[case when then end]]></category>
		<category><![CDATA[if statement]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ternary operator]]></category>

		<guid isPermaLink="false">http://iwebdevel.com/?p=363</guid>
		<description><![CDATA[While working on a proxy checker tool for one of my projects, I was struggling on how to execute a conditional query on my SQLite database to update a column only if its value is greater than 0 (it would be pointless in my case to let the script update the column with negative values). [...]


Related posts:<ol><li><a href='http://iwebdevel.com/2009/06/08/wordpress-easily-reset-your-account-password-using-mysql-and-php/' rel='bookmark' title='WordPress: Easily Reset Your Account Password Using MySQL and PHP'>WordPress: Easily Reset Your Account Password Using MySQL and PHP</a></li>
<li><a href='http://iwebdevel.com/2009/06/23/php-error-call-to-a-member-function-fetch_assoc-on-a-non-object-in/' rel='bookmark' title='PHP Error: Call to a member function fetch_assoc() on a non-object in'>PHP Error: Call to a member function fetch_assoc() on a non-object in</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fiwebdevel.com%2F2010%2F02%2F03%2Fsqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fiwebdevel.com%2F2010%2F02%2F03%2Fsqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite%2F&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>While working on a proxy checker tool for one of my projects, I was struggling on how to execute a conditional query on my SQLite database to update a column only if its value is greater than 0 (it would be pointless in my case to let the script update the column with negative values).</p>
<p>In Mysql one would do like this (we use the ternary operator <strong>IF(to_check_expression&gt;0,expression1,expression2)</strong>):</p>
<p><code><strong>update table_name set column_name=IF((column_name-1)&gt;0,(column_name-1),0)</strong></code></p>
<p>However, in SQLite this method will not work. Instead I had to use the <strong>case when (condition) then expression1 else expression2 end</strong> method.</p>
<p>The above query in MySQL can be rewritten like this in SQLite:</p>
<p><code><strong>update table_name set column_name=case when (column_name-1)&gt;0 then (column_name-1) else 0 end</strong></code></p>
<p>That&#8217;s it. I hope it helps someone!</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=24&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-gmail">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=52&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=6&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=4&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=SQLite%2C+MySQL%2C+PHP%3A+Ternary+operator+%28IF%28%29+statement%29+in+MySQL+and+SQLite&amp;link=http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/&amp;notes=While%20working%20on%20a%20proxy%20checker%20tool%20for%20one%20of%20my%20projects%2C%20I%20was%20struggling%20on%20how%20to%20execute%20a%20conditional%20query%20on%20my%20SQLite%20database%20to%20update%20a%20column%20only%20if%20its%20value%20is%20greater%20than%200%20%28it%20would%20be%20pointless%20in%20my%20case%20to%20let%20the%20script%20update%20the%20column%20with%20negative%20values%29.%0D%0A%0D%0AIn%20Mysql%20o&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>



<p>Related posts:<ol><li><a href='http://iwebdevel.com/2009/06/08/wordpress-easily-reset-your-account-password-using-mysql-and-php/' rel='bookmark' title='WordPress: Easily Reset Your Account Password Using MySQL and PHP'>WordPress: Easily Reset Your Account Password Using MySQL and PHP</a></li>
<li><a href='http://iwebdevel.com/2009/06/23/php-error-call-to-a-member-function-fetch_assoc-on-a-non-object-in/' rel='bookmark' title='PHP Error: Call to a member function fetch_assoc() on a non-object in'>PHP Error: Call to a member function fetch_assoc() on a non-object in</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

