<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Get_to_the_point&amp;feed=atom&amp;action=history</id>
		<title>Get to the point - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Get_to_the_point&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Get_to_the_point&amp;action=history"/>
		<updated>2013-05-22T23:53:06Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Get_to_the_point&amp;diff=789&amp;oldid=prev</id>
		<title>Connor: Created page with &quot;&lt;h3&gt;Movie Database: The JOIN&lt;/h3&gt; &lt;p&gt; The obvious questions about this database involve all three tables. Who appear in such-and-such a film, or which films has so-and-so appe...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Get_to_the_point&amp;diff=789&amp;oldid=prev"/>
				<updated>2012-07-11T08:48:52Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h3&amp;gt;Movie Database: The JOIN&amp;lt;/h3&amp;gt; &amp;lt;p&amp;gt; The obvious questions about this database involve all three tables. Who appear in such-and-such a film, or which films has so-and-so appe...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h3&amp;gt;Movie Database: The JOIN&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The obvious questions about this database involve all three tables.&lt;br /&gt;
Who appear in such-and-such a film, or which films has so-and-so appeared&lt;br /&gt;
in. In fact we can answer some of these questions using nested &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt;&lt;br /&gt;
statements that have already been covered.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;A join allows us to link two tables which have a &amp;quot;common&amp;quot; field. The&lt;br /&gt;
id field of the actor table is referred to by the actorid field of the&lt;br /&gt;
casting table. A join of these tables on these fields produces a&lt;br /&gt;
table which includes all of the attributes of both tables.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Joining two tables&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
Join casting and actor on actorid/id         &lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT * FROM casting JOIN actor&lt;br /&gt;
          ON casting.actorid=actor.id&lt;br /&gt;
  WHERE actor.name='John Hurt'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='ans'&amp;gt;&lt;br /&gt;
SELECT * FROM casting JOIN actor&lt;br /&gt;
          ON casting.actorid=actor.id&lt;br /&gt;
  WHERE actor.name='John Hurt'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The result of the above gives one row for every element of the casting table which&lt;br /&gt;
relates to John Hurt.&lt;br /&gt;
In addition to the actorid we have the name of the actor involved.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;Joining three tables&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The it makes sense to join the above table with the movie table. The&lt;br /&gt;
obvious field to join on is the movieid field.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
Join casting and actor on actorid/id         &lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT * FROM&lt;br /&gt;
   movie JOIN casting ON movie.id=movieid&lt;br /&gt;
         JOIN actor   ON actorid=actor.id&lt;br /&gt;
  WHERE actor.name='John Hurt'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='ans'&amp;gt;&lt;br /&gt;
SELECT * FROM&lt;br /&gt;
   movie JOIN casting ON movie.id=movieid&lt;br /&gt;
         JOIN actor   ON actorid=actor.id&lt;br /&gt;
  WHERE actor.name='John Hurt'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The result now again has one row for every element of the casting table,&lt;br /&gt;
this time we get details of the movies as well as the name of the actor.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice that in some cases we refer to a field using just the field name&lt;br /&gt;
(e.g. &amp;lt;code&amp;gt;actorid&amp;lt;/code&amp;gt;) and sometimes we preceed the field name with&lt;br /&gt;
the table name (e.g. &amp;lt;code&amp;gt;casting.actorid&amp;lt;/code&amp;gt;). You must include the&lt;br /&gt;
 table name if the field names are not unique.&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Connor</name></author>	</entry>

	</feed>