SlideShare a Scribd company logo
1 of 16
Joins
• To retrieve data from multiple tables on the basis of
common field or particular condition, we use join.
Types of join
1. Inner join
• Inner join is a simple join in which result is based on
match data as per conditions specified in query.
• It uses as equivalent operator.
• This type of join can be used in the situation where
selecting only those rows that have common values
• Syntax:
Select column_name list from tablename1 inner join
tablename2 on
tablename1.column_name=tablename2.column_name;
2. Outer join
• If rows/ records does not satisfy the condition, the
record will not appear in the result.
• So, outer join is used to select or to display both
matched as well as unmatched data from tables.
i. Left outer join
ii. Right outer join
iii. Full outer join
i. Left outer join
• The left outer join returns the table with matched
data of two tables, then remaining rows of left table
and null values for non matching data of right table.
Syntax:
Select column_name list from tablename1 left outer
join tablename2 on
tablename1.columnname=tablename2.columnname;
Null
ii. Right outer join
• The right outer join returns the table with matched data of two
tables, then remaining rows of right table and null values for
non matching data of left table.
Syntax:
Select column_name list from tablename1 right outer join
tablename2 on
tablename1.columnname=tablename2.columnname;
Null
iii. Full outer join
The full outer join returns the result table with matched
data of two tables, then remaining rows of both left and
right tables and null values for non matching data of
both tables.
Syntax:
Select column_name list from tablename1 full outer
join tablename2 on
tablename1.columnname=tablename2.columnname;
3. Cross join
• This type of join combines each row from left table
with every row in right.
• This join creates redundant data. Cross join will
produce huge result set which is not desirable.
• The result of cross join can be filtered by using where
clause which may produce equivalent result of inner
join.
Syntax:
Select column_name list from tablename1 cross join
tablename2;
4. Self join
• Self join is used to join table with itself.
• In this join participating table appears twice after
from clause and is followed by alias for table that
select column name in join condition are returned
from the table.
• In this join, the rows which satisfy the condition are
returned from the table.
• Consider Ex.
Employee
- Display information of employee who’s commission is greater
than salary after adding 15000 in commission.
- Select * from employee a, employee b where a.
Commission+15000 > b. salary and a.empno=b.empno;
- O/P
Empno Salary Commission
111 35000 10000
112 24000 10000
113 40000 8000
Empno Salary Commission
112 24000 10000
Empno Salary Commission
112 24000 10000
3.4 Views
• View can be defined as a logical part of total data
present in the table.
• Once table or data is created, the user need to access
view columns or rows from the table to be displayed.
If user need to access view columns or rows from the
table, programmer need to write different programs
to avoid this views are created.
• View consists of rows and columns just as table. That
is views are definitions built on top of other tables
and do not hold data themselves.
• If data is changing in underlying table or multiple
tables, it can also be built on the top on another view.
Advantages of view
• Ease of use
• Space saving
• Additional data security
Syntax:
Create VIEW <ViewName> AS select columnname1,
columnname2,……, columnname n from table name
where columnname=expression;
Updating views
• View can be used to update the data present in
created view as well as in base table.
• All updates to a base table is immediately reflected in
all views as well as if view is updated the changes are
also reflected in base table.
• Syntax:
Update <view_name> set <given changes> where
predicates;
Views and joins
• Views can be created by joining multiple tables.
• But in these types of views, there is a limitation to
perform insert, delete and update operations on view.
Views and sub queries
Views can be created by writing sub queries using any
comparison or relational or logical operators.
Dropping view
• Drop view is used to remove or drop the created view
from database.
• Syntax
Drop view viewname;
Restriction on view
i. When view is created by joining two different
tables, then we cannot apply insert, delete, update
commands on that view.
ii. We cannot use order by clause with views.
iii. Views cannot be created on temporary tables.
iv. You cannot use associate rules with views.

More Related Content

Similar to SQL Joins and View.pptx (20)

Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
 
Advanced Excel ppt
Advanced Excel pptAdvanced Excel ppt
Advanced Excel ppt
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
 
SQL Join's
SQL Join'sSQL Join's
SQL Join's
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
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
 
Mssql
MssqlMssql
Mssql
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
 
Advance Microsoft Office Excel Course.pptx
Advance Microsoft Office Excel Course.pptxAdvance Microsoft Office Excel Course.pptx
Advance Microsoft Office Excel Course.pptx
 
OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptx
 
Les04
Les04Les04
Les04
 
Joins and unions
Joins and unionsJoins and unions
Joins and unions
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
joins in dbms its describes about how joins are important and necessity in d...
joins in dbms  its describes about how joins are important and necessity in d...joins in dbms  its describes about how joins are important and necessity in d...
joins in dbms its describes about how joins are important and necessity in d...
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
(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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
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
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(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
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
(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
 
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
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
(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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Recently uploaded (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
(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...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
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...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(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...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(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
 
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
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

SQL Joins and View.pptx

  • 1. Joins • To retrieve data from multiple tables on the basis of common field or particular condition, we use join. Types of join 1. Inner join • Inner join is a simple join in which result is based on match data as per conditions specified in query. • It uses as equivalent operator. • This type of join can be used in the situation where selecting only those rows that have common values
  • 2. • Syntax: Select column_name list from tablename1 inner join tablename2 on tablename1.column_name=tablename2.column_name;
  • 3. 2. Outer join • If rows/ records does not satisfy the condition, the record will not appear in the result. • So, outer join is used to select or to display both matched as well as unmatched data from tables. i. Left outer join ii. Right outer join iii. Full outer join
  • 4. i. Left outer join • The left outer join returns the table with matched data of two tables, then remaining rows of left table and null values for non matching data of right table. Syntax: Select column_name list from tablename1 left outer join tablename2 on tablename1.columnname=tablename2.columnname; Null
  • 5. ii. Right outer join • The right outer join returns the table with matched data of two tables, then remaining rows of right table and null values for non matching data of left table. Syntax: Select column_name list from tablename1 right outer join tablename2 on tablename1.columnname=tablename2.columnname; Null
  • 6. iii. Full outer join The full outer join returns the result table with matched data of two tables, then remaining rows of both left and right tables and null values for non matching data of both tables. Syntax: Select column_name list from tablename1 full outer join tablename2 on tablename1.columnname=tablename2.columnname;
  • 7. 3. Cross join • This type of join combines each row from left table with every row in right. • This join creates redundant data. Cross join will produce huge result set which is not desirable. • The result of cross join can be filtered by using where clause which may produce equivalent result of inner join. Syntax: Select column_name list from tablename1 cross join tablename2;
  • 8. 4. Self join • Self join is used to join table with itself. • In this join participating table appears twice after from clause and is followed by alias for table that select column name in join condition are returned from the table. • In this join, the rows which satisfy the condition are returned from the table.
  • 9. • Consider Ex. Employee - Display information of employee who’s commission is greater than salary after adding 15000 in commission. - Select * from employee a, employee b where a. Commission+15000 > b. salary and a.empno=b.empno; - O/P Empno Salary Commission 111 35000 10000 112 24000 10000 113 40000 8000 Empno Salary Commission 112 24000 10000 Empno Salary Commission 112 24000 10000
  • 10. 3.4 Views • View can be defined as a logical part of total data present in the table. • Once table or data is created, the user need to access view columns or rows from the table to be displayed. If user need to access view columns or rows from the table, programmer need to write different programs to avoid this views are created. • View consists of rows and columns just as table. That is views are definitions built on top of other tables and do not hold data themselves. • If data is changing in underlying table or multiple tables, it can also be built on the top on another view.
  • 11. Advantages of view • Ease of use • Space saving • Additional data security
  • 12. Syntax: Create VIEW <ViewName> AS select columnname1, columnname2,……, columnname n from table name where columnname=expression;
  • 13. Updating views • View can be used to update the data present in created view as well as in base table. • All updates to a base table is immediately reflected in all views as well as if view is updated the changes are also reflected in base table. • Syntax: Update <view_name> set <given changes> where predicates;
  • 14. Views and joins • Views can be created by joining multiple tables. • But in these types of views, there is a limitation to perform insert, delete and update operations on view. Views and sub queries Views can be created by writing sub queries using any comparison or relational or logical operators.
  • 15. Dropping view • Drop view is used to remove or drop the created view from database. • Syntax Drop view viewname;
  • 16. Restriction on view i. When view is created by joining two different tables, then we cannot apply insert, delete, update commands on that view. ii. We cannot use order by clause with views. iii. Views cannot be created on temporary tables. iv. You cannot use associate rules with views.