<?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=Equi_Join&amp;feed=atom&amp;action=history</id>
		<title>Equi Join - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Equi_Join&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Equi_Join&amp;action=history"/>
		<updated>2013-06-20T11:12:26Z</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=Equi_Join&amp;diff=1079&amp;oldid=prev</id>
		<title>Marek at 13:21, 12 July 2012</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Equi_Join&amp;diff=1079&amp;oldid=prev"/>
				<updated>2012-07-12T13:21:42Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:21, 12 July 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How do you use Equi Join to join two tables with the same name?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How do you use Equi Join to join two tables with the same name?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class='ht'&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class='ht'&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=params&amp;gt;schema:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;gisq&lt;/del&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class=params&amp;gt;schema:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;scott&lt;/ins&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I am trying to join two tables with the same name. I am required to use an inner join&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I am trying to join two tables with the same name. I am required to use an inner join&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Equi_Join&amp;diff=1074&amp;oldid=prev</id>
		<title>Marek at 13:18, 12 July 2012</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Equi_Join&amp;diff=1074&amp;oldid=prev"/>
				<updated>2012-07-12T13:18:46Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:18, 12 July 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How do you use Equi Join to join two tables with the same name?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How do you use Equi Join to join two tables with the same name?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class='ht'&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class='ht'&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;div class=params&amp;gt;schema:gisq&amp;lt;/div&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I am trying to join two tables with the same name. I am required to use an inner join&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I am trying to join two tables with the same name. I am required to use an inner join&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 14:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 15:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;does not show up in the results.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;does not show up in the results.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang=sql class='tidy'&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang=sql class='tidy'&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;gt;DROP TABLE employee&amp;lt;/source&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;source lang=sql class='setup'&amp;gt;&amp;lt;/source&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/source&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang='sql' class='def e-access'&amp;gt;CREATE TABLE employee(&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang='sql' class='def e-access'&amp;gt;CREATE TABLE employee(&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; employee_id INTEGER PRIMARY KEY,&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; employee_id INTEGER PRIMARY KEY,&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Equi_Join&amp;diff=839&amp;oldid=prev</id>
		<title>Marek: Created page with &quot;How do you use Equi Join to join two tables with the same name? &lt;div class='ht'&gt; &lt;div&gt; I am trying to join two tables with the same name. I am required to use an inner join Al...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Equi_Join&amp;diff=839&amp;oldid=prev"/>
				<updated>2012-07-11T11:47:36Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;How do you use Equi Join to join two tables with the same name? &amp;lt;div class=&amp;#039;ht&amp;#039;&amp;gt; &amp;lt;div&amp;gt; I am trying to join two tables with the same name. I am required to use an inner join Al...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;How do you use Equi Join to join two tables with the same name?&lt;br /&gt;
&amp;lt;div class='ht'&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
I am trying to join two tables with the same name. I am required to use an inner join&lt;br /&gt;
Also I need to show the managers name.&lt;br /&gt;
Question is:&lt;br /&gt;
Join the employee table with the employee table and department table.&lt;br /&gt;
Show the employee id, name, dept code, manager id, manager name, &lt;br /&gt;
managers department code, and name for that (mgr's) department.&lt;br /&gt;
&lt;br /&gt;
We have a self join, each copy of the table is given an &amp;quot;alias&amp;quot; - here we&lt;br /&gt;
use w for the worker and b for the boss. We can treat these as different tables.&lt;br /&gt;
You get an inner join by default - this means that Robin (who has no boss)&lt;br /&gt;
does not show up in the results.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='tidy'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-access'&amp;gt;CREATE TABLE employee(&lt;br /&gt;
  employee_id INTEGER PRIMARY KEY,&lt;br /&gt;
  first_name VARCHAR(10),&lt;br /&gt;
  dept_code VARCHAR(10),&lt;br /&gt;
  manager_id INTEGER REFERENCES employee);&lt;br /&gt;
INSERT INTO employee VALUES (1,'Robin','Eng',NULL);&lt;br /&gt;
INSERT INTO employee VALUES (2,'Jon','SoC',1);&lt;br /&gt;
INSERT INTO employee VALUES (3,'Andrew','SoC',2);&lt;br /&gt;
INSERT INTO employee VALUES (4,'Alison','SoC',2);&lt;br /&gt;
SELECT w.first_name as worker, b.first_name as boss&lt;br /&gt;
 FROM employee w, employee b&lt;br /&gt;
WHERE w.manager_id = b.employee_id&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-oracle'&amp;gt;CREATE TABLE employee(&lt;br /&gt;
  employee_id INTEGER PRIMARY KEY,&lt;br /&gt;
  first_name VARCHAR(10),&lt;br /&gt;
  dept_code VARCHAR(10),&lt;br /&gt;
  manager_id INTEGER REFERENCES employee);&lt;br /&gt;
INSERT INTO employee VALUES (1,'Robin','Eng',NULL);&lt;br /&gt;
INSERT INTO employee VALUES (2,'Jon','SoC',1);&lt;br /&gt;
INSERT INTO employee VALUES (3,'Andrew','SoC',2);&lt;br /&gt;
INSERT INTO employee VALUES (4,'Alison','SoC',2);&lt;br /&gt;
SELECT w.first_name as worker, b.first_name as boss&lt;br /&gt;
 FROM employee w, employee b&lt;br /&gt;
WHERE w.manager_id = b.employee_id&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-mysql'&amp;gt;CREATE TABLE employee(&lt;br /&gt;
  employee_id INTEGER PRIMARY KEY,&lt;br /&gt;
  first_name VARCHAR(10),&lt;br /&gt;
  dept_code VARCHAR(10),&lt;br /&gt;
  manager_id INTEGER REFERENCES employee);&lt;br /&gt;
INSERT INTO employee VALUES (1,'Robin','Eng',NULL);&lt;br /&gt;
INSERT INTO employee VALUES (2,'Jon','SoC',1);&lt;br /&gt;
INSERT INTO employee VALUES (3,'Andrew','SoC',2);&lt;br /&gt;
INSERT INTO employee VALUES (4,'Alison','SoC',2);&lt;br /&gt;
SELECT w.first_name as worker, b.first_name as boss&lt;br /&gt;
 FROM employee w, employee b&lt;br /&gt;
WHERE w.manager_id = b.employee_id&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-sqlserver'&amp;gt;USE scott;&lt;br /&gt;
CREATE TABLE employee(&lt;br /&gt;
  employee_id INTEGER PRIMARY KEY,&lt;br /&gt;
  first_name VARCHAR(10),&lt;br /&gt;
  dept_code VARCHAR(10),&lt;br /&gt;
  manager_id INTEGER REFERENCES employee);&lt;br /&gt;
INSERT INTO employee VALUES (1,'Robin','Eng',NULL);&lt;br /&gt;
INSERT INTO employee VALUES (2,'Jon','SoC',1);&lt;br /&gt;
INSERT INTO employee VALUES (3,'Andrew','SoC',2);&lt;br /&gt;
INSERT INTO employee VALUES (4,'Alison','SoC',2);&lt;br /&gt;
SELECT w.first_name as worker, b.first_name as boss&lt;br /&gt;
 FROM employee w, employee b&lt;br /&gt;
WHERE w.manager_id = b.employee_id&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;CREATE TABLE employee(&lt;br /&gt;
  employee_id INTEGER PRIMARY KEY,&lt;br /&gt;
  first_name VARCHAR(10),&lt;br /&gt;
  dept_code VARCHAR(10),&lt;br /&gt;
  manager_id INTEGER REFERENCES employee);&lt;br /&gt;
INSERT INTO employee VALUES (1,'Robin','Eng',NULL);&lt;br /&gt;
INSERT INTO employee VALUES (2,'Jon','SoC',1);&lt;br /&gt;
INSERT INTO employee VALUES (3,'Andrew','SoC',2);&lt;br /&gt;
INSERT INTO employee VALUES (4,'Alison','SoC',2);&lt;br /&gt;
SELECT w.first_name as worker, b.first_name as boss&lt;br /&gt;
 FROM employee w, employee b&lt;br /&gt;
WHERE w.manager_id = b.employee_id&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SELECT Ref}}&lt;/div&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	</feed>