Subqueries and Views
Subqueries and Views
Nahida Nazir
Types of View
Simple View
Complex View
Nahida Nazir
Simple View
Simple View in SQL is the view created
by involving only single table.
Simple View in SQL is the view created
by involving only single table.
In Simple View one cannot include NOT
NULL columns from base table
Nahida Nazir
Syntax for View
create view prof_view as
select name, department,salary
from professor // first run this statements
select* from prof_view
Nahida Nazir
Insert Values in Views
Nahida Nazir
Update View
update pro_view
set department='computer_engineering'
where name='raj';
Nahida Nazir
Remove a row from View
delete from pro_view
where name='pc‘
Drop view
drop view pro_view
Nahida Nazir
Complex View
Complex View is created by involving
more than one table i.e., multiple tables
get projected in Complex view.
NOT NULL columns can be included in
complex view.
Nahida Nazir
Sub queries
A Subquery or Inner query or a Nested
query is a query within another SQL
query and embedded within the WHERE
clause.
Subqueries can be used with the
SELECT, INSERT, UPDATE, and
DELETE statements along with the
operators like =, <, >, >=, <=, IN,
BETWEEN, etc.
Nahida Nazir
Rules for Sub queries
Subqueries must be enclosed within
parentheses.
An ORDER BY command cannot be
used in a subquery, although the main
query can use an ORDER BY.
Nahida Nazir