Joins and unions in Sql

636 views

Published on

Joins and unions in Sql

Published in: Education, Technology, Travel
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
636
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Joins and unions in Sql

  1. 1. Joins and Unions in SQL Server
  2. 2. JOIN Operator An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.
  3. 3. 1.Cross joins SELECT <column list> FROM <left joined table> CROSS JOIN <right joined table> 2. Inner joins SELECT <column list> FROM <left joined table> [INNER] JOIN <right joined table> ON <join condition> 3. Outer joins SELECT <column list> FROM <left joined table> LEFT|RIGHT|FULL [OUTER] JOIN <right joined table> ON <join condition>
  4. 4. UNION Operator The UNION operator is used to combine the result-set of two or more SELECT statements. Syntax SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
  5. 5. Difference between SQL JOIN and UNION 1.) The columns of joining tables may be different in JOIN but in UNION the number of columns and order of columns of all queries must be same. 2.) The UNION puts rows from queries after each other( puts vertically ) but JOIN puts the column from queries after each other (puts horizontally), i.e. it makes a cartesian product.
  6. 6. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  7. 7. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550
  8. 8. THE END

×