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.
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.