<?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>sql - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Fri, 01 Jun 2018 11:58:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>sql - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Understanding Different Types of SQL JOINs with Examples</title>
		<link>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/</link>
					<comments>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Nandan]]></dc:creator>
		<pubDate>Thu, 14 Dec 2017 08:38:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Joins]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tsql]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1343</guid>

					<description><![CDATA[<p>SQL JOINs are used to retrieve set of information from two or more different tables based upon certain common values between them. We use joins to combine tables with Select SQL statements. Related Articles: Read UNION vs UNION ALL Logon&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/">Understanding Different Types of SQL JOINs with Examples</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SQL JOINs are used to retrieve set of information from two or more different tables based upon certain common values between them. We use joins to combine tables with Select SQL statements.</p>
<p><em><strong><span style="color: #800000;">Related Articles:</span></strong></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/difference-between-union-and-union-all-operators/" target="_blank" rel="noopener">Read UNION vs UNION ALL</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/create-logon-trigger-restrict-sysadmin-logins-connect-sql-server-given-time-interval/" target="_blank" rel="noopener">Logon Trigger to Restrict sysadmin logins</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/table-row-count-showing-incorrect-value-sys-partitions-dmv-sys-dm_db_partition_stats/" target="_blank" rel="noopener">Why rou count showing incorrect value in sys.partitions?</a></strong></li>
</ul>
<h3><span style="color: #333399;"><strong>Types of Joins</strong></span></h3>
<p><strong> </strong>There are four types of Joins and each type is having separate ways to retrieve data.</p>
<ul>
<li><strong>Inner Join</strong></li>
<li><strong>Right Join</strong></li>
<li><strong>Left Join</strong></li>
<li><strong>Full Join</strong></li>
</ul>
<p>We will use two tables Employees and Leavesdetails to explain you each type of Joins with example. The details of both tables are given below.</p>
<p><strong>Table Employees:</strong></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1345" src="http://techyaz.com/wp-content/uploads/2017/12/1-Employees-Table.png" alt="Employees Table" width="378" height="196" /></p>
<p><strong>Table LeavesDetails:</strong></p>
<p><img decoding="async" class="aligncenter wp-image-1346" src="http://techyaz.com/wp-content/uploads/2017/12/2-LeaveDetails-Table.png" alt="LeavesDetails Table" width="380" height="194" /></p>
<p><strong> </strong>We will apply all types of Joins between these two tables to show you how they work. Let&#8217;s start with Inner Join.<strong> </strong></p>
<h5><span style="color: #333399;"><strong>Inner Join</strong><strong> </strong></span></h5>
<p>Inner join will show data that is matched between both joined tables. This is default join where result is based upon where clause and matched value from all rows fetch data. The visual representation of inner join will look like below image. You can see the coloured area that is common between both tables and that will be output of INNER JOIN.</p>
<p><img decoding="async" class="aligncenter wp-image-1347 " src="http://techyaz.com/wp-content/uploads/2017/12/3-Inner-Join.png" alt="Inner Join" width="244" height="150" /></p>
<p>As per above image, both tables Employees and Leavesdetails have been joined together to get output details for rows that are matched to each other.</p>
<pre><strong><span style="color: #0000ff;">SELECT *
FROM EMPLOYEES
<em>INNER JOIN</em> [dbo].[LeavesDetails]
ON [LeaveDetails].[Employeeid]=[Employees].[Employeeid]
</span></strong></pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1348" src="http://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join.png" alt="inner join example" width="806" height="214" srcset="https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join.png 806w, https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join-300x80.png 300w, https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join-768x204.png 768w" sizes="auto, (max-width: 806px) 100vw, 806px" /></p>
<p><span style="color: #333399;"><strong>Right Join</strong></span></p>
<p>When we use Right Join keyword, it will return all rows from table 2 that is placed right side of <em>RIGHT JOIN</em> keyword and matched rows from table 1 that is mentioned just left to the <em>RIGHT JOIN</em> keyword in SQL statement. In right join, if rows do not match with table 1 it will return <strong>null</strong> value. Sometimes, we call it as Right Outer Join as well. The visual diagram of Right Join is given below.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1349" src="http://techyaz.com/wp-content/uploads/2017/12/6-Right-Join.png" alt="right join" width="217" height="145" /></p>
<p><strong>Example</strong></p>
<p>We can see Employees table is mentioned as table 2 and placed just right after keyword <em>RIGHT JOIN</em> and Leavesdetails table has been mentioned as table 1 that is just left to the keyword <em>RIGHT JOIN</em>.</p>
<pre><span style="color: #0000ff;"><strong>SELECT * FROM Leavesdetails
<em>RIGHT JOIN</em> Employees
ON [Employees].[Employeeid]=[Leavesdetails].[Employeeid]
</strong></span></pre>
<p>You can see all values have been displayed from table Employees  along with corresponding details from table 2 Leavesdetails whereas there is one null value row from table Leavesdetails because there is no matched entry for this row from Employees table.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1350" src="http://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join.png" alt="Right Join Example" width="725" height="226" srcset="https://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join.png 725w, https://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join-300x94.png 300w" sizes="auto, (max-width: 725px) 100vw, 725px" /></p>
<h5><span style="color: #333399;"><strong>Left Join</strong></span></h5>
<p>When we use <em>LEFT JOIN</em> keyword, it will return all rows from table 1 that is placed just before or left side to the <em>LEFT JOIN</em> keyword and matched rows from table 2 that is mentioned just right side to the <em>LEFT JOIN</em> keyword in SQL statement. In left join, if rows do not match with table 2 it will return <strong>null</strong> value. Left Join is also known as left outer join. You can see the visual representation of Left Join in below image.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1351" src="http://techyaz.com/wp-content/uploads/2017/12/8-Left-Join.png" alt="left join" width="242" height="146" /></p>
<p><strong>Example</strong></p>
<p>you can see, now Employee table is mentioned left side of <em>LEFT JOIN</em> keyword and Leavesdetails table is mentioned in right side of this keyword so Employee table will work as table 1 and Leavesdetails will work as table 2.</p>
<pre><span style="color: #0000ff;"><strong>SELECT *
FROM Employees
<em>LEFT JOIN</em> Leavesdetails
ON [Leavesdetails].[Employeeid]=[Employees].[Employeeid]
</strong></span></pre>
<p>We can see all records from Employees table along with its corresponding details from table 2 Leavesdetails whereas one null values from table2 that is Leavesdetails because it&#8217;s matching with the data presented in table 1 Employees table. As highlighted record does not exist in table 2 it is showing null value.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1352" src="http://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join.png" alt="Left Join Example" width="721" height="221" srcset="https://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join.png 721w, https://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join-300x92.png 300w" sizes="auto, (max-width: 721px) 100vw, 721px" /></p>
<h5><span style="color: #333399;"><strong>Full Join</strong></span></h5>
<p>When we use <em>FULL JOIN</em>, it fetches results from both tables when there is a match in either in left or right table. We can also say it is kind of combination of left and right join.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1353" src="http://techyaz.com/wp-content/uploads/2017/12/10-Full-Join.png" alt="full join" width="235" height="151" /></p>
<p><strong>Example</strong></p>
<p>As visual representation shows, it will show all records from Employees table and Leavesdetails table. You can see in below result set Employee Manvendra has not any leaves detail and same way Employee ID 108 has not any record in Employees table but both rows are showing their values.</p>
<pre><strong><span style="color: #0000ff;">SELECT *
FROM EMPLOYEES
<em>FULL JOIN</em> [dbo].[Leavesdetails] on [Leavesdetails].[Employeeid]=[Employees].[Employeeid]
</span></strong></pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1354" src="http://techyaz.com/wp-content/uploads/2017/12/9-Full-Join.png" alt="full join example" width="779" height="231" srcset="https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join.png 779w, https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join-300x89.png 300w, https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join-768x228.png 768w" sizes="auto, (max-width: 779px) 100vw, 779px" /><br />
I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/">Understanding Different Types of SQL JOINs with Examples</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
