SlideShare a Scribd company logo
SQL Fundamentals Oracle 11g
M U H A M M A D WA H E E D
O R AC L E DATA BA S E D E V E LO P E R
E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m
Lecture#7
SQL Joins/SELECT on Multiple Tables
Cartesian Product
2
Cartesian Product(cont’d)
•A Cartesian product is formed when
- A join condition is omitted
- A join condition is invalid
- All rows are joined to the all rows in second table
•To avoid it, use valid join condition in WHERE clause
3
Cartesian Product(cont’d)
•Example:
i- SELECT s.std_id, s.std_name,r.sub_id,r.obt_marks
FROM student s, result r;
ii- SELECT s.std_id, s.std_name,r.sub_id,r.obt_marks
FROM student s, result r
WHERE s.std_id = r.result_id;
4
Types of Joins
There are following commonly used joins:
•Equijoin
•Non-equijoin
•Outer join
•Self join
*Note: join condition is always mentioned in WHERE clause
5
Join Condition
6
Equijoin
7
Equijoin(cont’d)
•Example:
SELECT s.std_id, s.std_name, r.obt_marks
FROM student s, result r
WHERE s.std_id = r.std_id;
8
Equijoin(cont’d)
•Example(additional search with join):
SELECT s.std_id, s.std_name, r.obt_marks
FROM student s, result r
WHERE s.std_id = r.std_id
AND r.obt_marks>65;
9
Equijoin(cont’d)
•Example(more than two tables in join):
SELECT s.std_id, s.std_name,r.sub_id,r.obt_marks
FROM student s, result r, subject ss
WHERE s.std_id = r.std_id AND ss.sub_id = r.sub_id
AND r.obt_marks>65;
10
Non-Equijoin
•A join condition containing something other than equality
operator.
•Example:
SELECT t.tch_id, t.tch_name,t.salary,s.sal_grade
FROM teacher t, salary_grade s
WHERE t.salary BETWEEN s.min_sal AND s.max_sal;
11
Outer Join
•A join condition which is used to display those rows that doesn’t
meet join criteria.
•Outer join operator is plus sign ‘+’.
•There are two types of outer join
- Left outer join
- Right outer join
12
Outer Join(cont’d)
•Example(left join):
SELECT s.std_id, s.std_name, r.obt_marks
FROM student s, result r
WHERE s.std_id (+)= r.std_id;
•Example(right join):
SELECT s.std_id, s.std_name, s.dept_id
FROM student s, department d
WHERE s.dept_id = d.dept_id(+);
13
Self Join
•A join condition where a table having it’s own primary key
as foreign key in itself.
•Example: manager_id of employee table is employee_id
itself.
14
Self Join(cont’d)
•Example:
SELECT a.emp_id,a.emp_name,a.manager_id
FROM employee a,employee b
WHERE a.manager_id = b.emp_id;
15
Feedback/Suggestions?
Give your feedback at: m.waheed3668@gmail.com
The feedback I get is that my books are honest.
- Laurie Halse Anderson

More Related Content

PDF
Basics of SELECT Statement - Oracle SQL
PDF
SQL Functions - Oracle SQL Fundamentals
PDF
SQL Functions - Oracle SQL Fundamentals
PDF
SQL Subqueries - Oracle SQL Fundamentals
PDF
Oracle SQL Fundamentals - Lecture 3
PDF
SQL Readable Outputs - Oracle SQL Fundamentals
PDF
Data Manipulation(DML) and Transaction Control (TCL)
PDF
SQL Fundamentals - Lecture 2
Basics of SELECT Statement - Oracle SQL
SQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL Fundamentals
SQL Subqueries - Oracle SQL Fundamentals
Oracle SQL Fundamentals - Lecture 3
SQL Readable Outputs - Oracle SQL Fundamentals
Data Manipulation(DML) and Transaction Control (TCL)
SQL Fundamentals - Lecture 2

What's hot (20)

PPT
PPTX
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
PPTX
Basics of c programming cit r.sandhiya
PPTX
STRUCTURE OF SQL QUERIES
PPT
20120810 tsql tips
PDF
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
DOC
Unit 5 (1)
PPTX
Getting Started with Regular Expressions In MarcEdit
PPTX
Select Clause
PPT
358 33 powerpoint-slides_6-strings_chapter-6
PPTX
Array & Exception Handling in C# (CSharp)
PPTX
ADVANCE ITT BY PRASAD
DOC
Mandatory sql functions for beginners
PPTX
concept of Array, 1D & 2D array
PPTX
PPTX
Advanced SQL Webinar
PPTX
Arrays In C++
PPT
358 33 powerpoint-slides_7-structures_chapter-7
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
Basics of c programming cit r.sandhiya
STRUCTURE OF SQL QUERIES
20120810 tsql tips
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
Unit 5 (1)
Getting Started with Regular Expressions In MarcEdit
Select Clause
358 33 powerpoint-slides_6-strings_chapter-6
Array & Exception Handling in C# (CSharp)
ADVANCE ITT BY PRASAD
Mandatory sql functions for beginners
concept of Array, 1D & 2D array
Advanced SQL Webinar
Arrays In C++
358 33 powerpoint-slides_7-structures_chapter-7
Ad

Similar to SQL Joins - Oracle SQL Fundamentals (20)

PPTX
SQL Operators.pptx
PPT
Unit04 dbms
PPT
SQL Introduction to displaying data from multiple tables
PDF
Relational model
PPT
relational algebra and it's implementation
PPT
SQL- Introduction to MySQL
PPTX
Sql.pptx
PPT
ch3.ppt
PPT
DBMS unit 3.ppt semester 4 btech aktu 2024
PDF
Introduction to sql.pdf Database Systems
PPT
Basic concept of c++
PPTX
SQL Operators.pptx
PPT
ch3.ppt
PDF
PPT
ch3.ppt
PPT
ch3.ppt
PPT
Introduction to SQL
PDF
0808.pdf
PDF
0808.pdf
SQL Operators.pptx
Unit04 dbms
SQL Introduction to displaying data from multiple tables
Relational model
relational algebra and it's implementation
SQL- Introduction to MySQL
Sql.pptx
ch3.ppt
DBMS unit 3.ppt semester 4 btech aktu 2024
Introduction to sql.pdf Database Systems
Basic concept of c++
SQL Operators.pptx
ch3.ppt
ch3.ppt
ch3.ppt
Introduction to SQL
0808.pdf
0808.pdf
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25-Week II
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
Approach and Philosophy of On baking technology

SQL Joins - Oracle SQL Fundamentals