<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title><![CDATA[SitePoint Forums - Databases & MySQL]]></title>
		<link>http://www.sitepoint.com/forums/</link>
		<description><![CDATA[Using a database such as MySQL, Oracle or SQLite to store your website's data? Learn about common issues and pitfalls, the correct use of indexes, normalisation and much more.]]></description>
		<language>en</language>
		<lastBuildDate>Thu, 23 May 2013 10:34:06 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.sitepoint.com/forums/images/sitepoint/misc/rss.png</url>
			<title><![CDATA[SitePoint Forums - Databases & MySQL]]></title>
			<link>http://www.sitepoint.com/forums/</link>
		</image>
		<item>
			<title>Online school admission system</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1078324-Online-school-admission-system&amp;goto=newpost</link>
			<pubDate>Thu, 23 May 2013 05:14:48 GMT</pubDate>
			<description><![CDATA[Hello programmers! 
I have been given a project to make an online school admission system, but I don't have much ideas how to do that. So, I need your help. What things I should consider and how the look of the website should be and how to maintain the database? What to understand first? etc 
So,...]]></description>
			<content:encoded><![CDATA[<div>Hello programmers!<br />
I have been given a project to make an online school admission system, but I don't have much ideas how to do that. So, I need your help. What things I should consider and how the look of the website should be and how to maintain the database? What to understand first? etc<br />
So, please help me as much as you can. By suggesting some samples that you have etc.<br />
Thanks.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>RizwanAhmedMemon</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1078324-Online-school-admission-system</guid>
		</item>
		<item>
			<title><![CDATA[Select AVG sale price of all items carried in 'A' when sales location <> 'A']]></title>
			<link>http://www.sitepoint.com/forums/showthread.php?1077547-Select-AVG-sale-price-of-all-items-carried-in-A-when-sales-location-lt-gt-A&amp;goto=newpost</link>
			<pubDate>Wed, 22 May 2013 20:14:11 GMT</pubDate>
			<description><![CDATA[I am having a hard time getting this to work right. Maybe you have a answer....  
 
 
I have several stores with a different set of items in each store, and all items are in at least two stores.  
 
--I want to find the average sale price of all items carried in 'store A' when the sales location...]]></description>
			<content:encoded><![CDATA[<div>I am having a hard time getting this to work right. Maybe you have a answer.... <br />
<br />
<br />
I have several stores with a different set of items in each store, and all items are in at least two stores. <br />
<br />
--I want to find the average sale price of all items carried in 'store A' when the sales location was another store and the date was in a certain range...so store &lt;&gt; 'store A' AND date BETWEEN '2013-xx-xx' AND '2013-xx-xx'... <br />
<br />
<br />
I have tried several things but mostly looking similar to this: <br />
<br />
--Select avg(sales price) FROM (SELECT * from sales where store &lt;&gt; 'store A' AND date BETWEEN '2013-xx-xx' AND '2013-xx-xx') AS sales WHERE item IN (SELECT item from sales where store = 'store A'); <br />
<br />
<br />
<br />
The goal is to compare average sales at store A with average sales of like items in different locations. I want to run for 30 stores to compare each location. Can anybody see a better way of getting my desired results. I feel like I might be taking the long road</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>Billiam80</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1077547-Select-AVG-sale-price-of-all-items-carried-in-A-when-sales-location-lt-gt-A</guid>
		</item>
		<item>
			<title>fetch the max and than if there is equal take max field</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1077117-fetch-the-max-and-than-if-there-is-equal-take-max-field&amp;goto=newpost</link>
			<pubDate>Wed, 22 May 2013 15:22:10 GMT</pubDate>
			<description>Hi, 
 
PHP: 
--------- 
CREATE TABLE IF NOT EXISTS ingredient( 
    id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, 
    food_id TINYINT UNSIGNED NOT NULL, 
    title VARCHAR(255) NOT NULL, 
    point TINYINT UNSIGNED NOT NULL, 
    score INT UNSIGNED DEFAULT 0,</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">CREATE&nbsp;TABLE&nbsp;</span><span style="color: #007700">IF&nbsp;</span><span style="color: #0000BB">NOT&nbsp;EXISTS&nbsp;ingredient</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">id&nbsp;TINYINT&nbsp;UNSIGNED&nbsp;NOT&nbsp;NULL&nbsp;AUTO_INCREMENT</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">food_id&nbsp;TINYINT&nbsp;UNSIGNED&nbsp;NOT&nbsp;NULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">title&nbsp;VARCHAR</span><span style="color: #007700">(</span><span style="color: #0000BB">255</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">NOT&nbsp;NULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">point&nbsp;TINYINT&nbsp;UNSIGNED&nbsp;NOT&nbsp;NULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">score&nbsp;INT&nbsp;UNSIGNED&nbsp;</span><span style="color: #007700">DEFAULT&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">PRIMARY&nbsp;KEY&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">id</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">UNIQUE&nbsp;KEY&nbsp;unique_ingredient_title&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">title</span><span style="color: #007700">)<br />)&nbsp;</span><span style="color: #0000BB">ENGINE</span><span style="color: #007700">=</span><span style="color: #0000BB">InnoDB&nbsp;</span><span style="color: #007700">DEFAULT&nbsp;</span><span style="color: #0000BB">CHARSET</span><span style="color: #007700">=</span><span style="color: #0000BB">utf8</span><span style="color: #007700">;&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code><hr />
</div>so with this query I got the ingredient with the<br />
max score <br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">SELECT&nbsp;id</span><span style="color: #007700">,</span><span style="color: #0000BB">food_id</span><span style="color: #007700">,</span><span style="color: #0000BB">title</span><span style="color: #007700">,</span><span style="color: #0000BB">MAX</span><span style="color: #007700">(</span><span style="color: #0000BB">score</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">FROM&nbsp;ubi_ingredient&nbsp;<br />GROUP&nbsp;BY&nbsp;food_id&nbsp;<br /></span>
</span>
</code></code><hr />
</div>but if there is a ingredient<br />
with the same score I want the one with<br />
the max score and I don' find the way ^^<br />
<br />
Can you help me, please ?<br />
Thanks in advance.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>whisher</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1077117-fetch-the-max-and-than-if-there-is-equal-take-max-field</guid>
		</item>
		<item>
			<title>Very Simple Subquery Returning Strange Results</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1077098-Very-Simple-Subquery-Returning-Strange-Results&amp;goto=newpost</link>
			<pubDate>Wed, 22 May 2013 13:48:58 GMT</pubDate>
			<description><![CDATA[All I want is a single random value from this MySQL query. Both the outer inner and outer queries reference the same table but I'm assigning them different aliases. Yet, this query is still performing like a correlated subquery, often returning multiple results. 
 
 
Code: 
--------- 
select img.*...]]></description>
			<content:encoded><![CDATA[<div>All I want is a single random value from this MySQL query. Both the outer inner and outer queries reference the same table but I'm assigning them different aliases. Yet, this query is still performing like a correlated subquery, often returning multiple results.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">select img.* from images img where img.image_id = (select floor(max(i.image_id) * rand()) + 1 from images i)</code><hr />
</div>The inner query performs as expected if extracted and ran by itself, returning only a single random value.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>brandonBuster</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1077098-Very-Simple-Subquery-Returning-Strange-Results</guid>
		</item>
		<item>
			<title>Random Sort Order on 2nd Column?</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1075461-Random-Sort-Order-on-2nd-Column&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 16:15:00 GMT</pubDate>
			<description><![CDATA[The following MySQL query returns a listing of Articles for each Sub-Section of my website... 
 
SELECT ap.ds_subsection_slug, a.slug, a.heading, a.summary, a.image 
FROM article AS a 
INNER JOIN article_placement AS ap 
ON a.slug = ap.article_slug 
WHERE ap.sd_section_slug = 'finance' 
AND...]]></description>
			<content:encoded><![CDATA[<div>The following MySQL query returns a listing of Articles for each Sub-Section of my website...<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code SQL:</div>
                <hr /><code class="bbcode_code"><div class="sql" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #993333; font-weight: bold;">SELECT</span> ap<span style="color: #66cc66;">.</span>ds_subsection_slug<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>slug<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>heading<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>summary<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>image
<span style="color: #993333; font-weight: bold;">FROM</span> article <span style="color: #993333; font-weight: bold;">AS</span> a
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> article_placement <span style="color: #993333; font-weight: bold;">AS</span> ap
<span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>slug <span style="color: #66cc66;">=</span> ap<span style="color: #66cc66;">.</span>article_slug
<span style="color: #993333; font-weight: bold;">WHERE</span> ap<span style="color: #66cc66;">.</span>sd_section_slug <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'finance'</span>
<span style="color: #993333; font-weight: bold;">AND</span> ap<span style="color: #66cc66;">.</span>ds_dimension_slug <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'featured-finance'</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> ap<span style="color: #66cc66;">.</span>ds_subsection_slug<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>slug</pre></div></code><hr />
</div> <br />
<br />
My goal is to &quot;randomize&quot; the order in which Articles are displayed in a given Sub-Section.  (Hopefully this will encourage Users to read more Articles?!)<br />
<br />
<b>Is there some way in MySQL, to return a result-set first sorted alphabetically by Sub-Section, but then sorted *randomly* by Article??</b><br />
<br />
Sincerely,<br />
<br />
<br />
Debbie</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>DoubleDee</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1075461-Random-Sort-Order-on-2nd-Column</guid>
		</item>
		<item>
			<title>PROBLEM WITH COMPLEX PHP MYSQL UPDATE</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1075455-PROBLEM-WITH-COMPLEX-PHP-MYSQL-UPDATE&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 15:08:23 GMT</pubDate>
			<description><![CDATA[Hi all, I've been working on a php script that update school classes in a mysql database. 
 
Below is the script i have worked on thus far and the images of how my database table is and how i want it to be after the update. Basically I want it to retain the "sub_class" when updating the "class"...]]></description>
			<content:encoded><![CDATA[<div>Hi all, I've been working on a php script that update school classes in a mysql database.<br />
<br />
Below is the script i have worked on thus far and the images of how my database table is and how i want it to be after the update. Basically I want it to retain the &quot;sub_class&quot; when updating the &quot;class&quot; from the &quot;dyn_class&quot;.<br />
<br />
<br />
<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code PHP:</div>
                <hr /><code class="bbcode_code"><div class="php" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$curYear</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$end_year</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curYear</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classA</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'JSS1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classB</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'JSS2'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classC</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'JSS3'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classD</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'SS1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classE</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'SS2'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classF</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'SS3'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$check_all</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` where d_class='<span style="color: #006699; font-weight: bold;">$classF</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$get_all</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query1</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='Senior-graduant', class='Senior-graduant', year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classF</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$check_all1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` order by `sub_class` desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$get_all1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass2</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$query2</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='<span style="color: #006699; font-weight: bold;">$classF</span>', class='<span style="color: #006699; font-weight: bold;">$classF</span><span style="color: #006699; font-weight: bold;">$subclass2</span>', year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classE</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$check_all2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` order by `sub_class` desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$get_all2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass3</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all2</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query3</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='<span style="color: #006699; font-weight: bold;">$classE</span>', class='<span style="color: #006699; font-weight: bold;">$classE</span><span style="color: #006699; font-weight: bold;">$subclass3</span>' , year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classD</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$check_all3</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` order by `sub_class` desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#40;</span><span style="color: #000088;">$get_all3</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass4</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all3</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query4</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='Junior-graduant', class='Junior-Graduant' , year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classC</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$check_all4</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` order by `sub_class` desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$get_all4</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass5</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all4</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query5</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='<span style="color: #006699; font-weight: bold;">$classC</span>', class='<span style="color: #006699; font-weight: bold;">$classC</span><span style="color: #006699; font-weight: bold;">$subclass5</span>' , year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classB</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$check_all5</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from `student` order by `sub_class` desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$get_all5</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check_all5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$subclass6</span><span style="color: #339933;">=</span> <span style="color: #000088;">$get_all5</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sub_class'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query6</span><span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update student set d_class='<span style="color: #006699; font-weight: bold;">$classB</span>', class='<span style="color: #006699; font-weight: bold;">$classB</span><span style="color: #006699; font-weight: bold;">$subclass6</span>' , year='<span style="color: #006699; font-weight: bold;">$end_year</span>' where d_class='<span style="color: #006699; font-weight: bold;">$classA</span>' and year='<span style="color: #006699; font-weight: bold;">$curYear</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;Classes updated successfully!&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Could not update classes!'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></code><hr />
</div> <br />
This is how it looks like before the update.<br />
<br />
<a href="http://www.sitepoint.com/forums/attachment.php?attachmentid=62203&amp;d=1369147894"  title="Name:  normal.jpg
Views: 3
Size:  51.5 KB">normal.jpg</a><br />
<br />
<br />
<br />
This is how I want it to look like after the update.<br />
<br />
<a href="http://www.sitepoint.com/forums/attachment.php?attachmentid=62204&amp;d=1369147921"  title="Name:  UPDATED.jpg
Views: 0
Size:  53.9 KB">UPDATED.jpg</a><br />
<br />
Thanks as i await your responses.</div>


	<div style="padding:10px">

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.sitepoint.com/forums/images/sitepoint/attach/jpg.gif" alt="File Type: jpg" />
	<a href="http://www.sitepoint.com/forums/attachment.php?attachmentid=62203&amp;d=1369147894" target="_blank">normal.jpg</a> 
(51.5 KB)
</li><li>
	<img class="inlineimg" src="http://www.sitepoint.com/forums/images/sitepoint/attach/jpg.gif" alt="File Type: jpg" />
	<a href="http://www.sitepoint.com/forums/attachment.php?attachmentid=62204&amp;d=1369147921" target="_blank">UPDATED.jpg</a> 
(53.9 KB)
</li>
			</ul>
			</fieldset>
	

	

	</div>
]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>kcay</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1075455-PROBLEM-WITH-COMPLEX-PHP-MYSQL-UPDATE</guid>
		</item>
		<item>
			<title>Calculate difference of values for records on outer ends of timeframe</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1075434-Calculate-difference-of-values-for-records-on-outer-ends-of-timeframe&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 12:38:23 GMT</pubDate>
			<description><![CDATA[Hy there, 
 
I'm working on a problem I can't seem te solve in MySQL. 
 
I have a table with snapshots of cummulative values. The information I need is the difference of those values within a timeframe. 
At the moment I use PHP to calculate thoses difference because I can't seem te get the min and...]]></description>
			<content:encoded><![CDATA[<div>Hy there,<br />
<br />
I'm working on a problem I can't seem te solve in MySQL.<br />
<br />
I have a table with snapshots of cummulative values. The information I need is the difference of those values within a timeframe.<br />
At the moment I use PHP to calculate thoses difference because I can't seem te get the min and max date from the table AND the values corresponding to those records.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">SELECT fms1.* <br />
FROM fms1 <br />
WHERE<br />
AND fms1.gps_unit_id = 114 <br />
AND fms1.created &gt;= &quot;2013-03-01 00:00:00&quot; <br />
ORDER BY fms1.created ASC <br />
LIMIT 1<br />
) UNION (<br />
SELECT fms1.* <br />
FROM fms1 <br />
&nbsp; &nbsp; WHERE fms1.gps_unit_id = 114 <br />
&nbsp; &nbsp; AND fms1.created &gt;= &quot;2013-03-01 00:00:00&quot; <br />
&nbsp; &nbsp; AND fms1.created &lt;= &quot;2013-03-01 23:59:59&quot; <br />
&nbsp; &nbsp; ORDER BY fms1.created DESC <br />
LIMIT 1<br />
)</code><hr />
</div>This way I get two rows returned for which I calculate the difference for each of those values. (say fms1.odometer, fms1.idle_time and so on)<br />
<br />
I tried something like this:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">SELECT<br />
&nbsp; &nbsp; fms1.*,<br />
&nbsp; &nbsp; max(fms1.created) AS MaxDate,<br />
&nbsp; &nbsp; min(fms1.created) AS MinDate<br />
FROM fms1<br />
WHERE fms1.created BETWEEN &quot;2013-03-01 00:00:00&quot; AND &quot;2013-03-01 23:59:59&quot; <br />
AND fms1.gps_unit_id = 114</code><hr />
</div>This does return the correct MinDate and MaxDate for the records on that day (over a 100), but it only returns the complete record for the MinDate. Which in this case is the correct one. You cannot sort the records by id, because causality is not guarantied.<br />
<br />
The thing I can't get my head around is how to select complete records based on the outcome of funtions like min() and max(). For instance if you use<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">SELECT<br />
&nbsp; &nbsp; max(fms1.created) AS MaxDate,<br />
&nbsp; &nbsp; min(fms1.created) AS MinDate<br />
FROM fms1<br />
WHERE fms1.created BETWEEN &quot;2013-03-01 00:00:00&quot; AND &quot;2013-03-01 23:59:59&quot; <br />
AND fms1.gps_unit_id = 114</code><hr />
</div>I do get the correct dates, but how to get the records belonging to those values? You can't use min() and max() in subqueries...<br />
<br />
Many thanks!</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>Hieronymus</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1075434-Calculate-difference-of-values-for-records-on-outer-ends-of-timeframe</guid>
		</item>
		<item>
			<title>upgrading mysql v4.1 to v5</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1075409-upgrading-mysql-v4-1-to-v5&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 11:17:25 GMT</pubDate>
			<description><![CDATA[Hi  
 
I'd like to update the MySQL on our web server from v4.1 to v5 so that my version of cpanel is easier to use. 
 
There may be other benefits too I guess. 
 
I have a 14 client's sites hosted on the web server that use mysql databases.   
 
8 of these are wordpress and joomla databases. The...]]></description>
			<content:encoded><![CDATA[<div>Hi <br />
<br />
I'd like to update the MySQL on our web server from v4.1 to v5 so that my version of cpanel is easier to use.<br />
<br />
There may be other benefits too I guess.<br />
<br />
I have a 14 client's sites hosted on the web server that use mysql databases.  <br />
<br />
8 of these are wordpress and joomla databases. The remainder are custom cms's I presume.<br />
<br />
1/ Do you think its a good idea for me to upgrade?<br />
<br />
2/ And if so do you have any tips for how I best proceed with the upgrade? <br />
<br />
Its a supported server to the server support team will perform the upgrade but of course I will be answerable to my clients if their websites stop working.<br />
<br />
Thanks</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>rooftop</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1075409-upgrading-mysql-v4-1-to-v5</guid>
		</item>
		<item>
			<title>Converting Database From LATIN-1 to UTF-8</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1074018-Converting-Database-From-LATIN-1-to-UTF-8&amp;goto=newpost</link>
			<pubDate>Mon, 20 May 2013 16:01:40 GMT</pubDate>
			<description><![CDATA[Hi there, 
 
I have an older database that is still using LATIN-1 as its encoding and I'd like to switch this to UTF-8 for the database, its tables, and their columns. 
 
Would these queries do the trick? 
 
alter table TABLENAME convert to CHARACTER SET utf8 COLLATE utf8_unicode_ci; 
[each...]]></description>
			<content:encoded><![CDATA[<div>Hi there,<br />
<br />
I have an older database that is still using LATIN-1 as its encoding and I'd like to switch this to UTF-8 for the database, its tables, and their columns.<br />
<br />
Would these queries do the trick?<br />
<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code mysql:</div>
                <hr /><code class="bbcode_code"><div class="mysql" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=ALTER"><span style="color: #990099; font-weight: bold;">alter</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TABLE"><span style="color: #990099; font-weight: bold;">table</span></a> TABLENAME <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=CONVERT"><span style="color: #990099; font-weight: bold;">convert</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TO"><span style="color: #990099; font-weight: bold;">to</span></a> CHARACTER <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> utf8 <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">COLLATE</span></a> utf8_unicode_ci<span style="color: #000033;">;</span>
<span style="color: #FF00FF;">&#91;</span>each <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TABLE"><span style="color: #990099; font-weight: bold;">table</span></a>...<span style="color: #FF00FF;">&#93;</span>
<span style="color: #FF00FF;">&#91;</span>each <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TABLE"><span style="color: #990099; font-weight: bold;">table</span></a>...<span style="color: #FF00FF;">&#93;</span>
<span style="color: #FF00FF;">&#91;</span>each <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TABLE"><span style="color: #990099; font-weight: bold;">table</span></a>...<span style="color: #FF00FF;">&#93;</span>
<a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=ALTER"><span style="color: #990099; font-weight: bold;">alter</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=DATABASE"><span style="color: #990099; font-weight: bold;">database</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SCHEMA"><span style="color: #990099; font-weight: bold;">SCHEMA</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=DEFAULT"><span style="color: #990099; font-weight: bold;">default</span></a> character <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">set</span></a> utf8 <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">COLLATE</span></a> utf8_unicode_ci<span style="color: #000033;">;</span></pre></div></code><hr />
</div> My questions are:<br />
<ul><li style="">Do I need to worry about any data/character loss upon conversion of these tables?  Or will the conversion be clean?<br /></li><li style="">What about columns that are currently storing HTML data?  This data has been htmlspecialchar()'ed in PHP.</li></ul>Furthermore, as I have been looking into encoding issues for this web app, I discovered that Apache's AddDefaultCharset has been set to ISO-8859-1 since the web app's inception.  So, any data that has been submitted to this database via web forms has had an encoding of ISO-8859-1.  This has now been set to UTF-8.<br />
<br />
In summary: web pages accepting ISO-8859-1 encoding into a LATIN-1 database switching to UTF-8 all around.<br />
<br />
Just want to make sure I don't lose any data before the flip. :) What do I need to be aware of?<br />
<br />
Thanks in advanced.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>Panduola</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1074018-Converting-Database-From-LATIN-1-to-UTF-8</guid>
		</item>
		<item>
			<title>Why does my while loop loop only 2 times instead of 10?</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1074010-Why-does-my-while-loop-loop-only-2-times-instead-of-10&amp;goto=newpost</link>
			<pubDate>Mon, 20 May 2013 14:58:53 GMT</pubDate>
			<description><![CDATA[Hi Guys, 
 
Here's my table data and my stored procedure in mySql 
Table checkval 
 
Code: 
--------- 
val 
---- 
5705]]></description>
			<content:encoded><![CDATA[<div>Hi Guys,<br />
<br />
Here's my table data and my stored procedure in mySql<br />
Table checkval<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">val<br />
----<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701</code><hr />
</div>Stored Procedure<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">BEGIN<br />
DECLARE x INT;<br />
DECLARE done INT DEFAULT FALSE;<br />
DECLARE myType INT;<br />
DECLARE cur1 CURSOR FOR select val from checkval;<br />
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;<br />
&nbsp;<br />
SET x = 10;<br />
&nbsp;<br />
WHILE x&nbsp; &gt;= 2 DO<br />
##############<br />
&nbsp;<br />
OPEN cur1;<br />
&nbsp;<br />
read_loop: LOOP<br />
IF done THEN<br />
LEAVE read_loop;<br />
END IF;<br />
&nbsp;<br />
FETCH cur1 INTO myType;<br />
insert into myType values (myType);<br />
&nbsp;<br />
&nbsp;<br />
END LOOP read_loop;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
CLOSE cur1;<br />
SET&nbsp; x = x-1; <br />
&nbsp;<br />
##################<br />
END WHILE;<br />
&nbsp;<br />
END</code><hr />
</div><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Current Output<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701--Loops only twice<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701</code><hr />
</div><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Desired Output<br />
5705 - Loops 8 times<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701<br />
5705<br />
5704<br />
5703<br />
5702<br />
5701</code><hr />
</div>In all of this, even when I specify a while loop starting at `10` and ending at `2`, why do I get my output only looped twice in the target table. I was hoping to see it repeated 8 times. Can you pls help me on this? I'm backward with stored procedures, so I guess I'm not putting something in the right place or something like that.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>Nordy</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1074010-Why-does-my-while-loop-loop-only-2-times-instead-of-10</guid>
		</item>
		<item>
			<title>Database Content Metadata</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1071140-Database-Content-Metadata&amp;goto=newpost</link>
			<pubDate>Sat, 18 May 2013 20:22:13 GMT</pubDate>
			<description>Hi All, 
 
I am trying to build a database which will find music that has similar features however to do such I need to enter metadata. I was wondering what is the best way to do such? Currently I have basic data like track name, genre, artist etc. However I want to go deeper than that and define...</description>
			<content:encoded><![CDATA[<div>Hi All,<br />
<br />
I am trying to build a database which will find music that has similar features however to do such I need to enter metadata. I was wondering what is the best way to do such? Currently I have basic data like track name, genre, artist etc. However I want to go deeper than that and define it as something like slow rockers or fast party music or even combining genres. What is the best way to achieve something like that in terms of storing the extra metadata that describes a track and then doing a query to find other tracks that match closely to it?<br />
<br />
Any help will be greatly appreciated.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>skelleex</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1071140-Database-Content-Metadata</guid>
		</item>
		<item>
			<title>INSERT SELECT statement</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1070994-INSERT-SELECT-statement&amp;goto=newpost</link>
			<pubDate>Sat, 18 May 2013 19:03:11 GMT</pubDate>
			<description>Hi there, 
 
I having a problem with a MySQL INSERT .. SELECT statement: 
 
Code: 
--------- 
INSERT INTO 
`products` 
( 
  `id`,</description>
			<content:encoded><![CDATA[<div>Hi there,<br />
<br />
I having a problem with a MySQL INSERT .. SELECT statement:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">INSERT INTO<br />
`products`<br />
(<br />
&nbsp; `id`, <br />
&nbsp; `image`, <br />
&nbsp; `title`, <br />
&nbsp; `description`, <br />
&nbsp; `price`, <br />
&nbsp; `VAT`, <br />
&nbsp; `related_products`<br />
) <br />
SELECT <br />
&nbsp; 'CR25', <br />
&nbsp; `id` FROM `images` WHERE `images`.`title` = 'Some Image Title', <br />
&nbsp; 'Product Title', <br />
&nbsp; 'Product Description', <br />
&nbsp; 4.99, <br />
&nbsp; 0, <br />
&nbsp; 'CR26'</code><hr />
</div>Throws an error:<br />
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'Product Title'<br />
<br />
I've also tried<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">INSERT INTO<br />
`products`<br />
(<br />
&nbsp; `id`, <br />
&nbsp; `image`, <br />
&nbsp; `title`, <br />
&nbsp; `description`, <br />
&nbsp; `price`, <br />
&nbsp; `VAT`, <br />
&nbsp; `related_products`<br />
) <br />
VALUES<br />
( <br />
&nbsp; 'CR25', <br />
&nbsp; (`id` FROM `images` WHERE `images`.`title` = 'Some Image Title'), <br />
&nbsp; 'Product Title', <br />
&nbsp; 'Product Description', <br />
&nbsp; 4.99, <br />
&nbsp; 0, <br />
&nbsp; 'CR26'<br />
)</code><hr />
</div>But I get a similar error message:<br />
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '<br />
<br />
As far as I can tell I'm using the correct syntax.<br />
<br />
Any ideas?<br />
<br />
Cheers<br />
M</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>mickyginger</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1070994-INSERT-SELECT-statement</guid>
		</item>
		<item>
			<title>AVG returning NULL - temporal values?</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1070871-AVG-returning-NULL-temporal-values&amp;goto=newpost</link>
			<pubDate>Sat, 18 May 2013 14:36:37 GMT</pubDate>
			<description><![CDATA[I have a MySQL query that works in 5.1 but not 5.5: 
 
SELECT AVG(sales) FROM `table` WHERE `name` = 'customer1' AND `date` > DATE_SUB(NOW(), INTERVAL 1 WEEK) 
 
I had a quick look on the reference manual and it appears to be due to a change of how it handles the date field, specifically: 
 
"The...]]></description>
			<content:encoded><![CDATA[<div>I have a MySQL query that works in 5.1 but not 5.5:<br />
<br />
SELECT AVG(sales) FROM `table` WHERE `name` = 'customer1' AND `date` &gt; DATE_SUB(NOW(), INTERVAL 1 WEEK)<br />
<br />
I had a quick look on the reference manual and it appears to be due to a change of how it handles the date field, specifically:<br />
<br />
<i>&quot;The SUM() and AVG() aggregate functions do not work with temporal values. (They convert the values to numbers, losing everything after the first nonnumeric character.) To work around this problem, convert to numeric units, perform the aggregate operation, and convert back to a temporal value.&quot;</i><br />
<br />
I understand that if I were to apply AVG() to the date, for example, I would need to convert the date field. But what do I do in this situation?</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>auth1</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1070871-AVG-returning-NULL-temporal-values</guid>
		</item>
		<item>
			<title>Updating the same table for date.</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1069865-Updating-the-same-table-for-date&amp;goto=newpost</link>
			<pubDate>Fri, 17 May 2013 04:07:44 GMT</pubDate>
			<description>Hi! 
 
I have a media table: 
 
id, endDateTime, expiryDateTime, fkCategoryId 
1, 2013-02-01 01:00:15, 2013-5-17 01:00:15, 3 
2, 2013-03-04 05:00:15, 2013-5-13 05:00:15, 3 
3, 2013-03-11 03:30:15, 2013-5-11 03:30:15, 4 
 
I want to increment the date by a number of weeks, say 4, from the...</description>
			<content:encoded><![CDATA[<div>Hi!<br />
<br />
I have a media table:<br />
<br />
id, endDateTime, expiryDateTime, fkCategoryId<br />
1, 2013-02-01 01:00:15, 2013-5-17 01:00:15, 3<br />
2, 2013-03-04 05:00:15, 2013-5-13 05:00:15, 3<br />
3, 2013-03-11 03:30:15, 2013-5-11 03:30:15, 4<br />
<br />
I want to increment the date by a number of weeks, say 4, from the expiryDateTime already in there. Here is what I do:<br />
<br />
UPDATE media SET expiryDateTime = DATE_ADD((SELECT expiryDateTime FROM media WHERE fkCategoryId = 3), INTERVAL 4 WEEK) WHERE fkCategoryId = 3<br />
<br />
But MYSQL says: You can't specify target table 'media' for update in FROM clause.<br />
<br />
I guess I cannot use the same table. What can I do?<br />
<br />
I would also like to check for NULL in the expiryDateTime field or 1000-01-01 00:00:00 and update it with endDateTime plus 4 weeks.<br />
<br />
What can I do?<br />
<br />
Thanks.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>firblazer</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1069865-Updating-the-same-table-for-date</guid>
		</item>
		<item>
			<title>Date interval</title>
			<link>http://www.sitepoint.com/forums/showthread.php?1069263-Date-interval&amp;goto=newpost</link>
			<pubDate>Thu, 16 May 2013 14:06:53 GMT</pubDate>
			<description><![CDATA[Hi guys, I need your help. 
 
Every two months, the day sixteen I need run this query select to recover the rows of previous months. 
 
If tried this version with current date (2013-05-16) I've the correct output: 
 
PHP: 
--------- 
mysql> SELECT 
	DATE_ADD(]]></description>
			<content:encoded><![CDATA[<div>Hi guys, I need your help.<br />
<br />
Every two months, the day sixteen I need run this query select to recover the rows of previous months.<br />
<br />
If tried this version with current date (2013-05-16) I've the correct output:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">mysql</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">SELECT<br />&nbsp;&nbsp;&nbsp;&nbsp;DATE_ADD</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">DATE_ADD</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(</span><span style="color: #0000BB">CURDATE</span><span style="color: #007700">()),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">INTERVAL&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">180&nbsp;DAY<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">INTERVAL&nbsp;1&nbsp;DAY<br /></span><span style="color: #007700">)&nbsp;AS&nbsp;</span><span style="color: #0000BB">first_day</span><span style="color: #007700">,<br />&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">MAKEDATE</span><span style="color: #007700">(</span><span style="color: #0000BB">YEAR</span><span style="color: #007700">(</span><span style="color: #0000BB">CURDATE</span><span style="color: #007700">())&nbsp;,&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">)<br />)&nbsp;AS&nbsp;</span><span style="color: #0000BB">last_day</span><span style="color: #007700">;<br />+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">first_day&nbsp;&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">last_day&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">|<br />+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">01</span><span style="color: #007700">-</span><span style="color: #0000BB">01&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">02</span><span style="color: #007700">-</span><span style="color: #0000BB">28&nbsp;</span><span style="color: #007700">|<br />+------------+------------+<br /></span><span style="color: #0000BB">1&nbsp;row&nbsp;in&nbsp;set&nbsp;<br /></span>
</span>
</code></code><hr />
</div>Instead if tried this version with date 2013-07-16 next time, I've this incorrect output; I need this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB"></span><span style="color: #007700">+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">first_day&nbsp;&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">LAST_DAY&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">|<br />+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">03</span><span style="color: #007700">-</span><span style="color: #0000BB">01&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">04</span><span style="color: #007700">-</span><span style="color: #0000BB">30&nbsp;</span><span style="color: #007700">|<br />+------------+------------+&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code><hr />
</div>But I've this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">mysql</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">SELECT<br />&nbsp;&nbsp;&nbsp;&nbsp;DATE_ADD</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">DATE_ADD</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(</span><span style="color: #DD0000">'2013-07-16'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">INTERVAL&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">180&nbsp;DAY<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">INTERVAL&nbsp;1&nbsp;DAY<br /></span><span style="color: #007700">)&nbsp;AS&nbsp;</span><span style="color: #0000BB">first_day</span><span style="color: #007700">,<br />&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">MAKEDATE</span><span style="color: #007700">(</span><span style="color: #0000BB">YEAR</span><span style="color: #007700">(</span><span style="color: #DD0000">'2013-07-16'</span><span style="color: #007700">)&nbsp;,&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">)<br />)&nbsp;AS&nbsp;</span><span style="color: #0000BB">LAST_DAY</span><span style="color: #007700">;<br />+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">first_day&nbsp;&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">LAST_DAY&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">|<br />+------------+------------+<br />|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">03</span><span style="color: #007700">-</span><span style="color: #0000BB">01&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">2013</span><span style="color: #007700">-</span><span style="color: #0000BB">02</span><span style="color: #007700">-</span><span style="color: #0000BB">28&nbsp;</span><span style="color: #007700">|<br />+------------+------------+<br /></span><span style="color: #0000BB">1&nbsp;row&nbsp;in&nbsp;set&nbsp;<br /></span>
</span>
</code></code><hr />
</div> I would really appreciate any help, thank you very much.</div>

]]></content:encoded>
			<category domain="http://www.sitepoint.com/forums/forumdisplay.php?88-Databases-amp-MySQL"><![CDATA[Databases & MySQL]]></category>
			<dc:creator>Miguel61</dc:creator>
			<guid isPermaLink="true">http://www.sitepoint.com/forums/showthread.php?1069263-Date-interval</guid>
		</item>
	</channel>
</rss>
