<?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>KrisWillis.com &#187; join</title>
	<atom:link href="http://www.kriswillis.com/index.php/tag/join/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kriswillis.com</link>
	<description></description>
	<lastBuildDate>Fri, 02 Jul 2010 13:10:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Table joins in MySQL with no matches</title>
		<link>http://www.kriswillis.com/index.php/2008/02/17/table-joins-in-mysql-with-no-matches/</link>
		<comments>http://www.kriswillis.com/index.php/2008/02/17/table-joins-in-mysql-with-no-matches/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 16:13:25 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[join]]></category>

		<guid isPermaLink="false">http://kriswillis.com/index.php/2008/02/17/table-joins-in-mysql-with-no-matches/</guid>
		<description><![CDATA[I consider my understanding of MySQL around the intermediate level, but when writing table joins in the past I have always used the &#8216;equi-join&#8217; method: SELECT t1.*, t2.`name` FROM t1, t2 WHERE t1.n = t2.n; Now, when a record for t2.n doesn&#8217;t exist, a row will not be returned. To solve this problem in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kriswillis.com/wp-content/uploads/2008/02/mysql_100x52-64.gif" title="MySQL Logo"><img src="http://kriswillis.com/wp-content/uploads/2008/02/mysql_100x52-64.gif" alt="MySQL Logo" class="alignright" align="right" border="0" /></a>I consider my understanding of MySQL around the intermediate level, but when writing table joins in the past I have always used the &#8216;equi-join&#8217; method:</p>
<p><code>SELECT t1.*, t2.`name` FROM t1, t2 WHERE t1.n = t2.n;</code></p>
<p>Now, when a record for t2.n doesn&#8217;t exist, a row will not be returned. To solve this problem in the past, I would have executed two separate queries and process the output with PHP &#8211; Not the most efficient solution.</p>
<p><span id="more-50"></span>Today I had to write a query on a relatively larger scale with a number of table joins. I knew for a fact that a few of these joins would not have matching data on all occasions and splitting one query into <em>x</em>  queries and then processing the results would not be a good idea in the slightest.</p>
<p>Searching Google yielded  bugger all on the subject, though that could have been down to my search criteria. The MySQL manual was helpful as usual (that&#8217;s sarcasm, by the way &#8211; They should take a page out of PHPs book, their manual is great), but with a mixture of the two I found the solution. Left joins.</p>
<p><code>SELECT t1.*, t2.`name` FROM t1 LEFT JOIN t2 ON t1.n = t2.n;</code></p>
<p>The above will return a row, even if there isn&#8217;t a match for t1.n = t2.n. Learning every day&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriswillis.com/index.php/2008/02/17/table-joins-in-mysql-with-no-matches/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
