<?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>Telasitio.com &#187; MySql</title>
	<atom:link href="http://www.telasitio.com/category/tech/mysql-tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.telasitio.com</link>
	<description>Technology, Games, Play, Jobs and everything else.</description>
	<lastBuildDate>Thu, 15 Sep 2011 18:27:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MySql Multiple Databases with Same Column Name</title>
		<link>http://www.telasitio.com/2009/11/mysql-multiple-databases-with-same-column-name/</link>
		<comments>http://www.telasitio.com/2009/11/mysql-multiple-databases-with-same-column-name/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:28:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://www.telasitio.com/?p=105</guid>
		<description><![CDATA[An interesting problem came one day as I was trying to get data from multiple databases.  As this is an easy topic, I had a hard time of getting it to display in my php code.  The problem is using the same column names on the tables.  While MySql allows this PHP has a hard [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting problem came one day as I was trying to get data from multiple databases.  As this is an easy topic, I had a hard time of getting it to display in my php code.  The problem is using the same column names on the tables.  While MySql allows this PHP has a hard time distinguishing.</p>
<p><strong>Example</strong></p>
<p>Lets say I have the 3 tables below Customer, Business and Invoice.  Notice that Customer and Business have the same columns.</p>
<p><code>Customer [id, name, phone]<br />
Business [id, name, phone]<br />
Invoice [id, business, customer, description]</code></p>
<p>A normal SQL SELECT statement for this would be</p>
<p><code>SELECT c.name, c.phone, b.name, b.phone, i.description<br />
FROM Customer c, Business b, Invoice i<br />
WHERE c.id=i.customer AND b.id=i.business</code></p>
<p>This would output the following columns.</p>
<p><code>MySql - RESULT [name, phone, name, phone, description]<br />
PHP - RESULT[name, phone, description]</code></p>
<p>Notice how it has name and phone twice on the MySql but when PHP looks at it as an array it has it only once.  Well we need to be able to use the other data from this statement.  To do this we will add a simple AS statement for the duplicate column names.</p>
<p><strong>Example</strong></p>
<p><code> SELECT c.name AS cname, c.phone AS cphone, b.name, b.phone, i.description<br />
FROM Customer c, Business b, Invoice i<br />
WHERE c.id=i.customer AND b.id=i.business</code></p>
<p><strong>RESULT</strong></p>
<p><code>MySql - RESULT [cname, cphone, name, phone, description]<br />
PHP - RESULT[cname, cphone, name, phone, description]</code></p>
<p>Take a look at the first 2 columns now.  Just adding the AS statement allowed the column to have different names that you can process.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.telasitio.com/2009/11/mysql-multiple-databases-with-same-column-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

