<?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>e-timpa.com &#187; Code and Backend</title>
	<atom:link href="http://www.e-timpa.com/articles/code-monkey/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.e-timpa.com</link>
	<description>It's nothing personal</description>
	<lastBuildDate>Sun, 23 Oct 2011 12:11:54 +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 and Inner joins &#8211; Simple Guide</title>
		<link>http://www.e-timpa.com/2008/03/25/just-join-it/</link>
		<comments>http://www.e-timpa.com/2008/03/25/just-join-it/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 11:34:52 +0000</pubDate>
		<dc:creator>Timps</dc:creator>
				<category><![CDATA[Code and Backend]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.e-timpa.com/?p=8</guid>
		<description><![CDATA[<img src='http://www.e-timpa.com/wp-content/140_sql.jpg' alt='' />]]></description>
			<content:encoded><![CDATA[<p>When writing code in MySQL, you don&#8217;t need to write inner joins.</p>
<p>Well you do, but you don&#8217;t need to say &#8220;INNER JOIN&#8221;</p>
<p>MySQL uses a dot syntax which makes our code so much easier.</p>
<p>Our example uses 3 tables with several columns each. A table of users, a table of DVD&#8217;s and a table showing who has borrowed what and when.</p>
<p>Users:  id,Name<br />
DVD: id, Title, genre<br />
loans: id,owner,Title,Date</p>
<p>So we have entries in all of these tables. And we want to retrieve a list of all of the loans.<br />
We use the name of the table a DOT and the name of the column.<br />
eg <em>Users.Name </em>will give us the Name value from the Users table.</p>
<p>The full query is</p>
<p>Select <strong>table.column</strong> from <strong>tables</strong> where <strong>table.column = table.column</strong></p>
<p>Select (all the fields we want) from ( list the tables here) where (list what equals what)</p>
<p><strong>Select Users.Name, DVD.Title, loans.Date from Users,DVD,Loans where loans.owner=Users.id, loans.Title=DVD.id</strong></p>
<p>The great part about this is, we only &#8220;select&#8221; the fields we want and can specify the criteria any other way we like. As long as you include all the tables involved, it will just work.<br />
These can get LONG and detailed, but without having to worry about &#8220;Inner Join THIS on THAT&#8221; we can use it easily. Here&#8217;s a real world example for a business who tracks internal device loans for quality testing.<br />
4 tables and  10 columns.<br />
You should be able to piece together their original table structure without too much trouble.</p>
<p>SELECT PSTT_trans.notes as out_notes, PSTT_users.name as username, PSTT_users.id as staff_number, PSTT_equip.id as equipment, PSTT_equip.name, PSTT_trans.id as transid, PSTT_trans.trackid as trackid, PSTT_trans.timestamp as out_time, PSTT_trans.owner_id as the_owner, PSTT_track.open as opentime <strong><br />
from<br />
</strong>PSTT_trans,PSTT_track,PSTT_equip,PSTT_users <strong><br />
WHERE<br />
</strong>PSTT_trans.equip_id = PSTT_equip.id AND PSTT_trans.owner_id = PSTT_users.id AND PSTT_trans.trackid = PSTT_track.id and PSTT_track.close is null and PSTT_trans.returned is null and PSTT_trans.direction = &#8216;out&#8217;<strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.e-timpa.com/2008/03/25/just-join-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

