SlideShare a Scribd company logo
Swapnali Pawar GCEKarad
Database Lab
Swapnali Pawar
JOINS in SQL
1
 Oracle JOINS are used to retrieve data from multiple tables.
 JOIN clause combines rows from two or more tables.
 creates a set of rows in a temporary table
Joins
Swapnali Pawar GCEKarad
2
Types of SQL JOIN
❖ EQUI JOIN
● EQUI JOIN is a simple SQL join.
● Uses the equal sign(=) as the comparison operator for
the condition
● NON EQUI JOIN uses comparison operator other than
the equal sign.
● The operators uses like >, <, >=, <= with the
condition.
❖ NON EQUI JOIN
Swapnali Pawar GCEKarad
3
Types of SQL EQUI JOIN
❖ INNER JOIN
❖ OUTER JOIN
● Returns only matched rows from the
participating tables.
● Match happened only at the key record of
participating tables.
● Returns all rows from one table and
● Matching rows from the secondary table and
● Comparison columns should be equal in both
the tables.
Swapnali Pawar GCEKarad
4
List of SQL JOINS
• INNER JOIN
• LEFT JOIN OR LEFT OUTER JOIN
• RIGHT JOIN OR RIGHT OUTER JOIN
• FULL OUTER JOIN
• NATURAL JOIN
• CROSS JOIN
• SELF JOIN
Swapnali Pawar GCEKarad
5
• SQL EQUI JOIN performs a JOIN against equality or
matching columns values of the associated tables. An
equal sign (=) is used as comparison operator in the
where clause to refer equality.
• You may also perform EQUI JOIN by using JOIN keyword
followed by ON keyword and then specifying names of the
columns along with their associated tables to check equality
• Syntax :
SELECT column_list FROM table1, table2....
WHERE table1.column_name = table2.column_name;
• Example –
SELECT student.name, student.id, record.class, record.city
FROM student, record WHERE student.city = record.city;
1. EQUI JOIN
Swapnali Pawar GCEKarad
6
1. EQUI JOIN 2nd way
Syntax :
SELECT column_list FROM table1 JOIN
table2 ON (join_condition)
Example –
SELECT student.name, student.id,
record.class, record.city FROM student
JOIN record ON student.city =
record.city;
Swapnali Pawar GCEKarad
7
Swapnali Pawar GCEKarad
8
Select * from Record;
Select * from Student; SELECT student.name, student.id, record.class,
record.city
FROM Student
JOIN Record
ON Student.city = Record.city;
Equi Join Example
Swapnali Pawar GCEKarad
9
NON-EQUI JOIN
• Non-equi joins are joins whose join conditions use
conditional operators other than equals
• The SQL NON EQUI JOIN uses comparison operator
instead of the equal sign like >, <, >=, <= along with
conditions.
• Syntax:
SELECT * FROM table_name1, table_name2
WHERE
table_name1.column [> | < | >= | <= ]
table_name2.column
Swapnali Pawar GCEKarad
10
Swapnali Pawar GCEKarad
11
• A self join is a join in which a table is joined with itself
(Unary relationships), specially when the table has a
FOREIGN KEY which references its own PRIMARY KEY.
• To join a table itself means that each row of the table is
combined with itself and with every other row of the
table.
• The self join can be viewed as a join of two copies of the
same table.
self join
Swapnali Pawar GCEKarad
12
table_A
SELECT *
FROM table_A X, table_A Y
WHERE X.A=Y.A;
Output
table_A
Swapnali Pawar GCEKarad
13
INNER JOIN (simple join)
• It is the most common type of join. Oracle INNER JOINS return all rows
from multiple tables where the join condition is met.
• Syntax
SELECT columns FROM table1 INNER JOIN table2 ON table1.column =
table2.column;
Swapnali Pawar GCEKarad
14
LEFT OUTER JOIN
• Another type of join is called an Oracle LEFT OUTER JOIN. This type of join
returns all rows from the LEFT-hand table specified in the ON condition
and only those rows from the other table where the joined fields are equal (join
condition is met).
• Syntax
SELECT columns FROM table1 LEFT [OUTER] JOIN table2 ON
table1.column = table2.column;
• In some databases, the LEFT OUTER JOIN keywords are replaced with LEFT
JOIN.
• The Oracle LEFT OUTER JOIN would return the all records from table1 and
only those records from table2 that intersect with table1.
Swapnali Pawar GCEKarad
15
RIGHT OUTER JOIN
• Another type of join is called an Oracle RIGHT OUTER JOIN. This type of join
returns all rows from the RIGHT-hand table specified in the ON condition
and only those rows from the other table where the joined fields are equal (join
condition is met).
• Syntax
SELECT columns FROM table1 RIGHT [OUTER] JOIN table2 ON
table1.column = table2.column;
• In some databases, the RIGHT OUTER JOIN keywords are replaced with
RIGHT JOIN.
• The Oracle RIGHT OUTER JOIN would return the all records from table2 and
only those records from table1 that intersect with table2.
Swapnali Pawar GCEKarad
16
FULL OUTER JOIN
• Another type of join is called an Oracle FULL OUTER
JOIN. This type of join returns all rows from the LEFT-
hand table and RIGHT-hand table with nulls in place
where the join condition is not met.
• Syntax
SELECT columns FROM table1 FULL [OUTER] JOIN table2 ON
table1.column = table2.column;
• In some databases, the FULL OUTER JOIN keywords are replaced
with FULL JOIN.
• The Oracle FULL OUTER JOIN would return the all records from
both table1 and table2.
Swapnali Pawar GCEKarad
17
Swapnali Pawar GCEKarad
ROLL_NO NAME ADDRESS
1 Swapnali karad
2 Rugveda Pune
3 Sarika Mumbai
4 Chaitrali kolhapur
5 Pratima karad
6 Rupali pune
COURSE
_ID
COURSE_NAME ROLL_NO
101 CSE 1
101 CSE 2
102 MCA 3
103 BCA 4
105 IT 5
106 ENTC 6
StudentTable CourseTable
Primary Key
Foreign Key
Join Operation requires at least 1 Common Attribute
18
Swapnali Pawar GCEKarad
1. Primary Key-
Create table student(Roll_no int primary key,
name varchar(20),
Address varchar(20));
2. Foreign Key-
Create table Course(course_id varchar(10),
course_name varchar(30)
Roll_no int references student(Roll_no));
3. Insert into student values(1,'Swapnali','karad');
4. Insert into Course values(101,'CSE',1);
1.CreateTables with primary key & Foreign Key
& insert Records in that
19
Swapnali Pawar GCEKarad
EQUI-JOIN-
Select student.roll_no,Name,Course_name from
student , course where
student.roll_no=course.roll_no;
select student.roll_no,Name,Course_name
from student JOIN course On
student.roll_no=course.roll_no;
20
Swapnali Pawar GCEKarad
NON-EQUI JOIN-
Select student.roll_no,Name,Course_name from student,course
where student.roll_no!=course.roll_no;
21
Swapnali Pawar GCEKarad
SELF JOIN
Select s1.roll_no,S1.name,S2.Address from Student S1,student
S2 where S1.Address=S2.Address and S1.Roll_no!=S2.roll_no;
22
Swapnali Pawar GCEKarad
INNER JOIN
select student.roll_no,name,course_id,course_name from
student Inner Join Course on
student.roll_no=course.roll_no;
23
Swapnali Pawar GCEKarad
LEFT OUTER JOIN
Select student.roll_no,name,course_id,course_name from
student Left Outer Join Course on student.roll_no=course.roll_no;
24
Swapnali Pawar GCEKarad
RIGHT OUTER JOIN-
Select student.roll_no,name,course_id,course_name from student
RIGHT OUTER JOIN Course on student.roll_no=course.roll_no;
25
Swapnali Pawar GCEKarad
FULL OUTER JOIN-
Select student.roll_no,name,course_id,course_name from student
FULL OUTER JOIN Course on student.roll_no=course.roll_no;
26
Swapnali Pawar GCEKarad
Student Activity
1.CreateTable Employee & Department using Primary key &
Foreign key Respectively.
ENO E_Name Address DeptNo Location ENO
Employee Department
2. Perform Equi Join,Non-Equi Join ,Self Join,Inner Join,Left Outer
Join,Right Outer Join,Full Outer Join on Employee & Deparment
Table.
3. Find Employee Name who worked in department having
Location same as Address
27
Swapnali Pawar GCEKarad
28

More Related Content

What's hot

Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ishucs
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
rehaniltifat
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
I L0V3 CODING DR
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
Nitesh Singh
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint home
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
MananPasricha
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
Ahmed Farag
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL
SQLSQL
Triggers
TriggersTriggers
Triggers
Pooja Dixit
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 

What's hot (20)

Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
joins in database
 joins in database joins in database
joins in database
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL
SQLSQL
SQL
 
Triggers
TriggersTriggers
Triggers
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 

Similar to SQL JOINS

Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
Priyabrat Kar
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Pooja Dixit
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
DataminingTools Inc
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
oracle content
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
Amrit Kaur
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
Brian Foote
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
Swapnali Pawar
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
MalaikaRahatQurashi
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
SangitaKabi
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Ali MasudianPour
 
types of SQL Joins
 types of SQL Joins types of SQL Joins
types of SQL Joins
vikram rajpurohit
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
bixxman
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Displaying data from multiple tables
Displaying data from multiple tablesDisplaying data from multiple tables
Displaying data from multiple tables
Syed Zaid Irshad
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 

Similar to SQL JOINS (20)

Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Query
QueryQuery
Query
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Rapid postgresql learning, part 3
Rapid postgresql learning, part 3
 
types of SQL Joins
 types of SQL Joins types of SQL Joins
types of SQL Joins
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Displaying data from multiple tables
Displaying data from multiple tablesDisplaying data from multiple tables
Displaying data from multiple tables
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 

More from Swapnali Pawar

Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
Swapnali Pawar
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
Swapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
Swapnali Pawar
 
Introduction to ios
Introduction to iosIntroduction to ios
Introduction to ios
Swapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
Swapnali Pawar
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Swapnali Pawar
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
Swapnali Pawar
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
Swapnali Pawar
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
Swapnali Pawar
 
Exception Handling
Exception Handling Exception Handling
Exception Handling
Swapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
Swapnali Pawar
 
Mobile Technology 3
Mobile Technology 3Mobile Technology 3
Mobile Technology 3
Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
Swapnali Pawar
 

More from Swapnali Pawar (19)

Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
 
Introduction to ios
Introduction to iosIntroduction to ios
Introduction to ios
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
 
Exception Handling
Exception Handling Exception Handling
Exception Handling
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
 
Mobile Technology 3
Mobile Technology 3Mobile Technology 3
Mobile Technology 3
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

SQL JOINS

  • 1. Swapnali Pawar GCEKarad Database Lab Swapnali Pawar JOINS in SQL 1
  • 2.  Oracle JOINS are used to retrieve data from multiple tables.  JOIN clause combines rows from two or more tables.  creates a set of rows in a temporary table Joins Swapnali Pawar GCEKarad 2
  • 3. Types of SQL JOIN ❖ EQUI JOIN ● EQUI JOIN is a simple SQL join. ● Uses the equal sign(=) as the comparison operator for the condition ● NON EQUI JOIN uses comparison operator other than the equal sign. ● The operators uses like >, <, >=, <= with the condition. ❖ NON EQUI JOIN Swapnali Pawar GCEKarad 3
  • 4. Types of SQL EQUI JOIN ❖ INNER JOIN ❖ OUTER JOIN ● Returns only matched rows from the participating tables. ● Match happened only at the key record of participating tables. ● Returns all rows from one table and ● Matching rows from the secondary table and ● Comparison columns should be equal in both the tables. Swapnali Pawar GCEKarad 4
  • 5. List of SQL JOINS • INNER JOIN • LEFT JOIN OR LEFT OUTER JOIN • RIGHT JOIN OR RIGHT OUTER JOIN • FULL OUTER JOIN • NATURAL JOIN • CROSS JOIN • SELF JOIN Swapnali Pawar GCEKarad 5
  • 6. • SQL EQUI JOIN performs a JOIN against equality or matching columns values of the associated tables. An equal sign (=) is used as comparison operator in the where clause to refer equality. • You may also perform EQUI JOIN by using JOIN keyword followed by ON keyword and then specifying names of the columns along with their associated tables to check equality • Syntax : SELECT column_list FROM table1, table2.... WHERE table1.column_name = table2.column_name; • Example – SELECT student.name, student.id, record.class, record.city FROM student, record WHERE student.city = record.city; 1. EQUI JOIN Swapnali Pawar GCEKarad 6
  • 7. 1. EQUI JOIN 2nd way Syntax : SELECT column_list FROM table1 JOIN table2 ON (join_condition) Example – SELECT student.name, student.id, record.class, record.city FROM student JOIN record ON student.city = record.city; Swapnali Pawar GCEKarad 7
  • 9. Select * from Record; Select * from Student; SELECT student.name, student.id, record.class, record.city FROM Student JOIN Record ON Student.city = Record.city; Equi Join Example Swapnali Pawar GCEKarad 9
  • 10. NON-EQUI JOIN • Non-equi joins are joins whose join conditions use conditional operators other than equals • The SQL NON EQUI JOIN uses comparison operator instead of the equal sign like >, <, >=, <= along with conditions. • Syntax: SELECT * FROM table_name1, table_name2 WHERE table_name1.column [> | < | >= | <= ] table_name2.column Swapnali Pawar GCEKarad 10
  • 12. • A self join is a join in which a table is joined with itself (Unary relationships), specially when the table has a FOREIGN KEY which references its own PRIMARY KEY. • To join a table itself means that each row of the table is combined with itself and with every other row of the table. • The self join can be viewed as a join of two copies of the same table. self join Swapnali Pawar GCEKarad 12
  • 13. table_A SELECT * FROM table_A X, table_A Y WHERE X.A=Y.A; Output table_A Swapnali Pawar GCEKarad 13
  • 14. INNER JOIN (simple join) • It is the most common type of join. Oracle INNER JOINS return all rows from multiple tables where the join condition is met. • Syntax SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column; Swapnali Pawar GCEKarad 14
  • 15. LEFT OUTER JOIN • Another type of join is called an Oracle LEFT OUTER JOIN. This type of join returns all rows from the LEFT-hand table specified in the ON condition and only those rows from the other table where the joined fields are equal (join condition is met). • Syntax SELECT columns FROM table1 LEFT [OUTER] JOIN table2 ON table1.column = table2.column; • In some databases, the LEFT OUTER JOIN keywords are replaced with LEFT JOIN. • The Oracle LEFT OUTER JOIN would return the all records from table1 and only those records from table2 that intersect with table1. Swapnali Pawar GCEKarad 15
  • 16. RIGHT OUTER JOIN • Another type of join is called an Oracle RIGHT OUTER JOIN. This type of join returns all rows from the RIGHT-hand table specified in the ON condition and only those rows from the other table where the joined fields are equal (join condition is met). • Syntax SELECT columns FROM table1 RIGHT [OUTER] JOIN table2 ON table1.column = table2.column; • In some databases, the RIGHT OUTER JOIN keywords are replaced with RIGHT JOIN. • The Oracle RIGHT OUTER JOIN would return the all records from table2 and only those records from table1 that intersect with table2. Swapnali Pawar GCEKarad 16
  • 17. FULL OUTER JOIN • Another type of join is called an Oracle FULL OUTER JOIN. This type of join returns all rows from the LEFT- hand table and RIGHT-hand table with nulls in place where the join condition is not met. • Syntax SELECT columns FROM table1 FULL [OUTER] JOIN table2 ON table1.column = table2.column; • In some databases, the FULL OUTER JOIN keywords are replaced with FULL JOIN. • The Oracle FULL OUTER JOIN would return the all records from both table1 and table2. Swapnali Pawar GCEKarad 17
  • 18. Swapnali Pawar GCEKarad ROLL_NO NAME ADDRESS 1 Swapnali karad 2 Rugveda Pune 3 Sarika Mumbai 4 Chaitrali kolhapur 5 Pratima karad 6 Rupali pune COURSE _ID COURSE_NAME ROLL_NO 101 CSE 1 101 CSE 2 102 MCA 3 103 BCA 4 105 IT 5 106 ENTC 6 StudentTable CourseTable Primary Key Foreign Key Join Operation requires at least 1 Common Attribute 18
  • 19. Swapnali Pawar GCEKarad 1. Primary Key- Create table student(Roll_no int primary key, name varchar(20), Address varchar(20)); 2. Foreign Key- Create table Course(course_id varchar(10), course_name varchar(30) Roll_no int references student(Roll_no)); 3. Insert into student values(1,'Swapnali','karad'); 4. Insert into Course values(101,'CSE',1); 1.CreateTables with primary key & Foreign Key & insert Records in that 19
  • 20. Swapnali Pawar GCEKarad EQUI-JOIN- Select student.roll_no,Name,Course_name from student , course where student.roll_no=course.roll_no; select student.roll_no,Name,Course_name from student JOIN course On student.roll_no=course.roll_no; 20
  • 21. Swapnali Pawar GCEKarad NON-EQUI JOIN- Select student.roll_no,Name,Course_name from student,course where student.roll_no!=course.roll_no; 21
  • 22. Swapnali Pawar GCEKarad SELF JOIN Select s1.roll_no,S1.name,S2.Address from Student S1,student S2 where S1.Address=S2.Address and S1.Roll_no!=S2.roll_no; 22
  • 23. Swapnali Pawar GCEKarad INNER JOIN select student.roll_no,name,course_id,course_name from student Inner Join Course on student.roll_no=course.roll_no; 23
  • 24. Swapnali Pawar GCEKarad LEFT OUTER JOIN Select student.roll_no,name,course_id,course_name from student Left Outer Join Course on student.roll_no=course.roll_no; 24
  • 25. Swapnali Pawar GCEKarad RIGHT OUTER JOIN- Select student.roll_no,name,course_id,course_name from student RIGHT OUTER JOIN Course on student.roll_no=course.roll_no; 25
  • 26. Swapnali Pawar GCEKarad FULL OUTER JOIN- Select student.roll_no,name,course_id,course_name from student FULL OUTER JOIN Course on student.roll_no=course.roll_no; 26
  • 27. Swapnali Pawar GCEKarad Student Activity 1.CreateTable Employee & Department using Primary key & Foreign key Respectively. ENO E_Name Address DeptNo Location ENO Employee Department 2. Perform Equi Join,Non-Equi Join ,Self Join,Inner Join,Left Outer Join,Right Outer Join,Full Outer Join on Employee & Deparment Table. 3. Find Employee Name who worked in department having Location same as Address 27