0% found this document useful (0 votes)
43 views

Subqueries and Views

Views in SQL are like virtual tables that have rows and columns. There are two main types of views: simple views that are created from a single table and complex views that are created by joining multiple tables. Simple views cannot include NOT NULL columns from the base table. Views can be used to select, insert, update, and delete data while providing security and abstraction. Subqueries are queries nested within other SQL queries that are used to filter or compare data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Subqueries and Views

Views in SQL are like virtual tables that have rows and columns. There are two main types of views: simple views that are created from a single table and complex views that are created by joining multiple tables. Simple views cannot include NOT NULL columns from the base table. Views can be used to select, insert, update, and delete data while providing security and abstraction. Subqueries are queries nested within other SQL queries that are used to filter or compare data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Views

 Views in SQL are kind of virtual tables.


 A view also has rows and columns as
they are in a real table in the database.

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

insert into prof_view


values('pc','botany',11000)
select*from prof_view

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

You might also like