SlideShare a Scribd company logo
1 of 9
Download to read offline
Database System Sunita M. Dol
Page 1
HANDOUT#06
Aim:
a) Views: Creation of views and update it
b) Join Relation: Inner Join, Left Outer Join, Right Outer Join, Full Outer Join
Theory:
Views
We define a view in SQL by using the create view command. To define a view, we must give
the view a name and must state the query that computes the view. The form of the create view
command is
create view v as <query expression>
where <query expression> is any legal query expression. The view name is represented by v.
Join Relation
Oracle JOINS are used to retrieve data from multiple tables. An Oracle JOIN is performed
whenever two or more tables are joined in a SQL statement.
There are 4 different types of Oracle joins:
• Oracle INNER JOIN (or sometimes called simple join)
• Oracle LEFT OUTER JOIN (or sometimes called LEFT JOIN)
• Oracle RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
• Oracle FULL OUTER JOIN (or sometimes called FULL JOIN)
INNER JOIN (simple join)
Visual Illustration
In this visual diagram, the Oracle INNER JOIN returns the shaded area:
The Oracle INNER JOIN would return the records where table1 and table2 intersect.
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).
Visual Illustration
Database System Sunita M. Dol
Page 2
In this visual diagram, the Oracle LEFT OUTER JOIN returns the shaded area:
The Oracle LEFT OUTER JOIN would return the all records from table1 and only those records
from table2 that intersect with table1.
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).
Visual Illustration
In this visual diagram, the Oracle RIGHT OUTER JOIN returns the shaded area:
The Oracle RIGHT OUTER JOIN would return the all records from table2 and only those
records from table1 that intersect with table2.
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.
Visual Illustration
In this visual diagram, the Oracle FULL OUTER JOIN returns the shaded area:
The Oracle FULL OUTER JOIN would return the all records from both table1 and table2.
Database System Sunita M. Dol
Page 3
Each of the variants of the join operations in SQL consists of a join type and a join condition.
The join condition defines which tuples in the two relations match and what attributes are present
in the result of the join. The join type defines how tuples in each relation that do not match any
tuple in the other relation (based on the join condition) are treated.
Figure 1 shows some of the allowed join types and join conditions. The first join type is the inner
join, and the other three are the outer joins.
Figure 1: Join types and join conditions.
Queries and Output:
Views
Create the view consisting of branch names and the names of customers who have either an
account or a loan at that branch.
SQL> create view all_customer as
2 (select branch_name, customer_name
3 from depositor, account
4 where depositor.account_number = account.account_number)
5 union
6 (select branch_name, customer_name
7 from borrower, loan
8 where borrower.loan_number = loan.loan_number);
View created.
SQL> select * from all_customer;
BRANCH_NAME CUSTOMER_NAME
--------------- --------------------
Brighton Johnson
Brighton Jones
Downtown Johnson
Downtown Jones
Downtown Williams
Database System Sunita M. Dol
Page 4
Mianus Curry
Mianus Smith
Perryridge Adams
Perryridge Hays
Redwood Lindsay
Redwood Smith
BRANCH_NAME CUSTOMER_NAME
--------------- --------------------
Round Hill Smith
Round Hill Turner
13 rows selected.
Find all customers of the Perryridge branch using view created in the above query.
SQL> select * from all_customer where branch_name='Perryridge';
BRANCH_NAME CUSTOMER_NAME
--------------- --------------------
Perryridge Adams
Perryridge Hays
Joined Relation:
Inner Join
Using NATURAL condition
SQL> select * from loan1;
LOAN_NUMBE BRANCH_NAME AMOUNT
---------- --------------- ----------
L-170 Downtown 3000
L-230 Redwood 4000
L-260 Perryridge 1700
Database System Sunita M. Dol
Page 5
SQL> select * from borrower1;
CUSTOMER_NAME LOAN_NUMBE
-------------------- ----------
Jones L-170
Smith L-230
Hayes L-155
SQL> select * from loan1 natural inner join borrower1;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
Using ON condition
SQL> select * from loan1 inner join borrower1 on loan1.loan_number=borrower1.loan_number;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
LOAN_NUMBE
---------- --------------- ---------- -------------------- ----------
L-170 Downtown 3000 Jones L-170
L-230 Redwood 4000 Smith L-230
Using USING condition
SQL> select * from loan1 join borrower1 using (loan_number);
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
Left Outer Join
Using NATURAL condition
SQL> select * from loan1;
LOAN_NUMBE BRANCH_NAME AMOUNT
---------- --------------- ----------
Database System Sunita M. Dol
Page 6
L-170 Downtown 3000
L-230 Redwood 4000
L-260 Perryridge 1700
SQL> select * from borrower1;
CUSTOMER_NAME LOAN_NUMBE
-------------------- ----------
Jones L-170
Smith L-230
Hayes L-155
SQL> select * from loan1 natural left outer join borrower1;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
L-260 Perryridge 1700
Using ON condition
SQL> select * from loan1 left outer join borrower1 on
loan1.loan_number=borrower1.loan_number;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
LOAN_NUMBE
---------- --------------- ---------- -------------------- ----------
L-170 Downtown 3000 Jones L-170
L-230 Redwood 4000 Smith L-230
L-260 Perryridge 1700
Using USING condition
SQL> select * from loan1 left outer join borrower1 using (loan_number);
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
Database System Sunita M. Dol
Page 7
L-230 Redwood 4000 Smith
L-260 Perryridge 1700
Right Outer Join
Using NATURAL condition
SQL> select * from loan1 natural right outer join borrower1;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
L-155 Hayes
Using ON condition
SQL> select * from loan1 right outer join borrower1 on
loan1.loan_number=borrower1.loan_number;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
LOAN_NUMBE
---------- --------------- ---------- -------------------- ----------
L-170 Downtown 3000 Jones L-170
L-230 Redwood 4000 Smith L-230
Hayes L-155
Using USING condition
SQL> select * from loan1 right outer join borrower1 using (loan_number);
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
L-155 Hayes
Full Outer Join
Using NATURAL condition
SQL> select * from loan1 natural full outer join borrower1;
Database System Sunita M. Dol
Page 8
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
L-260 Perryridge 1700
L-155 Hayes
Using ON condition
SQL> select * from loan1 full outer join borrower1 on
loan1.loan_number=borrower1.loan_number;
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
LOAN_NUMBE
---------- --------------- ---------- -------------------- ----------
L-170 Downtown 3000 Jones L-170
L-230 Redwood 4000 Smith L-230
L-260 Perryridge 1700
Hayes L-155
Using USING condition
SQL> select * from loan1 full outer join borrower1 using (loan_number);
LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME
---------- --------------- ---------- --------------------
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith
L-260 Perryridge 1700
L-155 Hayes
Conclusion:
We have written and executed queries in SQL using
• Views: Creation of views and update it
• Join Relation:
o Inner Join,
o Left Outer Join,
o Right Outer Join,
o Full Outer Join
Database System Sunita M. Dol
Page 9
References:
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) sixth edition.
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) fifth edition.
• http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/

More Related Content

What's hot (19)

STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sql
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Database queries
Database queriesDatabase queries
Database queries
 
ch3
ch3ch3
ch3
 
SQL
SQLSQL
SQL
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
SQL Views
SQL ViewsSQL Views
SQL Views
 

Similar to Assignment#06

Sq lite expressions
Sq lite expressionsSq lite expressions
Sq lite expressionspunu_82
 
Data Warehouse , Data Cube Computation
Data Warehouse   , Data Cube ComputationData Warehouse   , Data Cube Computation
Data Warehouse , Data Cube Computationsit20ad004
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview QuestionsBest SEO Tampa
 
Joining tables
Joining tablesJoining tables
Joining tablespunu_82
 
Sq lite functions
Sq lite functionsSq lite functions
Sq lite functionspunu_82
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line toolpunu_82
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questionsnagesh Rao
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi Portfoliomaywoo
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxssuser6bf2d1
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overviewgourav kottawar
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data ModelSmriti Jain
 
Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Ankit Dubey
 
Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Ankit Dubey
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMSkoolkampus
 

Similar to Assignment#06 (20)

Sq lite expressions
Sq lite expressionsSq lite expressions
Sq lite expressions
 
Data Warehouse , Data Cube Computation
Data Warehouse   , Data Cube ComputationData Warehouse   , Data Cube Computation
Data Warehouse , Data Cube Computation
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Joining tables
Joining tablesJoining tables
Joining tables
 
Sq lite functions
Sq lite functionsSq lite functions
Sq lite functions
 
Sql joins
Sql joinsSql joins
Sql joins
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line tool
 
SQL JOINS- Reena P V
SQL JOINS- Reena P VSQL JOINS- Reena P V
SQL JOINS- Reena P V
 
sfdfds
sfdfdssfdfds
sfdfds
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
 
DDL,DML,1stNF
DDL,DML,1stNFDDL,DML,1stNF
DDL,DML,1stNF
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi Portfolio
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overview
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01
 
Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01Sm relationaldatamodel-150423084157-conversion-gate01
Sm relationaldatamodel-150423084157-conversion-gate01
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 

More from Sunita Milind Dol (20)

9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment11
Assignment11Assignment11
Assignment11
 
Assignment10
Assignment10Assignment10
Assignment10
 
Assignment9
Assignment9Assignment9
Assignment9
 
Assignment8
Assignment8Assignment8
Assignment8
 
Assignment7
Assignment7Assignment7
Assignment7
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment5
Assignment5Assignment5
Assignment5
 
Assignment4
Assignment4Assignment4
Assignment4
 
Assignment3
Assignment3Assignment3
Assignment3
 
Assignment2
Assignment2Assignment2
Assignment2
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Assignment#06

  • 1. Database System Sunita M. Dol Page 1 HANDOUT#06 Aim: a) Views: Creation of views and update it b) Join Relation: Inner Join, Left Outer Join, Right Outer Join, Full Outer Join Theory: Views We define a view in SQL by using the create view command. To define a view, we must give the view a name and must state the query that computes the view. The form of the create view command is create view v as <query expression> where <query expression> is any legal query expression. The view name is represented by v. Join Relation Oracle JOINS are used to retrieve data from multiple tables. An Oracle JOIN is performed whenever two or more tables are joined in a SQL statement. There are 4 different types of Oracle joins: • Oracle INNER JOIN (or sometimes called simple join) • Oracle LEFT OUTER JOIN (or sometimes called LEFT JOIN) • Oracle RIGHT OUTER JOIN (or sometimes called RIGHT JOIN) • Oracle FULL OUTER JOIN (or sometimes called FULL JOIN) INNER JOIN (simple join) Visual Illustration In this visual diagram, the Oracle INNER JOIN returns the shaded area: The Oracle INNER JOIN would return the records where table1 and table2 intersect. 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). Visual Illustration
  • 2. Database System Sunita M. Dol Page 2 In this visual diagram, the Oracle LEFT OUTER JOIN returns the shaded area: The Oracle LEFT OUTER JOIN would return the all records from table1 and only those records from table2 that intersect with table1. 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). Visual Illustration In this visual diagram, the Oracle RIGHT OUTER JOIN returns the shaded area: The Oracle RIGHT OUTER JOIN would return the all records from table2 and only those records from table1 that intersect with table2. 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. Visual Illustration In this visual diagram, the Oracle FULL OUTER JOIN returns the shaded area: The Oracle FULL OUTER JOIN would return the all records from both table1 and table2.
  • 3. Database System Sunita M. Dol Page 3 Each of the variants of the join operations in SQL consists of a join type and a join condition. The join condition defines which tuples in the two relations match and what attributes are present in the result of the join. The join type defines how tuples in each relation that do not match any tuple in the other relation (based on the join condition) are treated. Figure 1 shows some of the allowed join types and join conditions. The first join type is the inner join, and the other three are the outer joins. Figure 1: Join types and join conditions. Queries and Output: Views Create the view consisting of branch names and the names of customers who have either an account or a loan at that branch. SQL> create view all_customer as 2 (select branch_name, customer_name 3 from depositor, account 4 where depositor.account_number = account.account_number) 5 union 6 (select branch_name, customer_name 7 from borrower, loan 8 where borrower.loan_number = loan.loan_number); View created. SQL> select * from all_customer; BRANCH_NAME CUSTOMER_NAME --------------- -------------------- Brighton Johnson Brighton Jones Downtown Johnson Downtown Jones Downtown Williams
  • 4. Database System Sunita M. Dol Page 4 Mianus Curry Mianus Smith Perryridge Adams Perryridge Hays Redwood Lindsay Redwood Smith BRANCH_NAME CUSTOMER_NAME --------------- -------------------- Round Hill Smith Round Hill Turner 13 rows selected. Find all customers of the Perryridge branch using view created in the above query. SQL> select * from all_customer where branch_name='Perryridge'; BRANCH_NAME CUSTOMER_NAME --------------- -------------------- Perryridge Adams Perryridge Hays Joined Relation: Inner Join Using NATURAL condition SQL> select * from loan1; LOAN_NUMBE BRANCH_NAME AMOUNT ---------- --------------- ---------- L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700
  • 5. Database System Sunita M. Dol Page 5 SQL> select * from borrower1; CUSTOMER_NAME LOAN_NUMBE -------------------- ---------- Jones L-170 Smith L-230 Hayes L-155 SQL> select * from loan1 natural inner join borrower1; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith Using ON condition SQL> select * from loan1 inner join borrower1 on loan1.loan_number=borrower1.loan_number; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME LOAN_NUMBE ---------- --------------- ---------- -------------------- ---------- L-170 Downtown 3000 Jones L-170 L-230 Redwood 4000 Smith L-230 Using USING condition SQL> select * from loan1 join borrower1 using (loan_number); LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith Left Outer Join Using NATURAL condition SQL> select * from loan1; LOAN_NUMBE BRANCH_NAME AMOUNT ---------- --------------- ----------
  • 6. Database System Sunita M. Dol Page 6 L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 SQL> select * from borrower1; CUSTOMER_NAME LOAN_NUMBE -------------------- ---------- Jones L-170 Smith L-230 Hayes L-155 SQL> select * from loan1 natural left outer join borrower1; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-260 Perryridge 1700 Using ON condition SQL> select * from loan1 left outer join borrower1 on loan1.loan_number=borrower1.loan_number; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME LOAN_NUMBE ---------- --------------- ---------- -------------------- ---------- L-170 Downtown 3000 Jones L-170 L-230 Redwood 4000 Smith L-230 L-260 Perryridge 1700 Using USING condition SQL> select * from loan1 left outer join borrower1 using (loan_number); LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones
  • 7. Database System Sunita M. Dol Page 7 L-230 Redwood 4000 Smith L-260 Perryridge 1700 Right Outer Join Using NATURAL condition SQL> select * from loan1 natural right outer join borrower1; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-155 Hayes Using ON condition SQL> select * from loan1 right outer join borrower1 on loan1.loan_number=borrower1.loan_number; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME LOAN_NUMBE ---------- --------------- ---------- -------------------- ---------- L-170 Downtown 3000 Jones L-170 L-230 Redwood 4000 Smith L-230 Hayes L-155 Using USING condition SQL> select * from loan1 right outer join borrower1 using (loan_number); LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-155 Hayes Full Outer Join Using NATURAL condition SQL> select * from loan1 natural full outer join borrower1;
  • 8. Database System Sunita M. Dol Page 8 LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-260 Perryridge 1700 L-155 Hayes Using ON condition SQL> select * from loan1 full outer join borrower1 on loan1.loan_number=borrower1.loan_number; LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME LOAN_NUMBE ---------- --------------- ---------- -------------------- ---------- L-170 Downtown 3000 Jones L-170 L-230 Redwood 4000 Smith L-230 L-260 Perryridge 1700 Hayes L-155 Using USING condition SQL> select * from loan1 full outer join borrower1 using (loan_number); LOAN_NUMBE BRANCH_NAME AMOUNT CUSTOMER_NAME ---------- --------------- ---------- -------------------- L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-260 Perryridge 1700 L-155 Hayes Conclusion: We have written and executed queries in SQL using • Views: Creation of views and update it • Join Relation: o Inner Join, o Left Outer Join, o Right Outer Join, o Full Outer Join
  • 9. Database System Sunita M. Dol Page 9 References: • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) sixth edition. • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) fifth edition. • http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/