SlideShare a Scribd company logo
1 of 28
Download to read offline
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 (20)

Sql join
Sql  joinSql  join
Sql join
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Cursors
CursorsCursors
Cursors
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
Triggers
TriggersTriggers
Triggers
 
Join
JoinJoin
Join
 

Similar to SQL JOINS

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
 
Join query
Join queryJoin query
Join query
 
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
 

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 ComputingSwapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architectureSwapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demoSwapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidSwapnali 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.1Swapnali 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 MC1514Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesSwapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting LabSwapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scriptingSwapnali 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

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

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