Subqueries

A sub query is a form of an SQL statement that appears inside another SQL statement. It is also termed as nested query. The statement containing a sub query is called a parent statement. The parent statement uses the rows returned by the sub query.
It can be used by the following commands:-

Ex:-     Create table salesorder(ono number(5),cno number(5),dat date);
Insert into salesorder values(1,6,’12-apr-02’);
Insert into salesorder values (2,2,’25-dec-02’);
Insert into salesorder values (3,7,’03-oct-02’);
Insert into salesorder values (4,5,’2-apr-02’);
Insert into salesorder values (5,2,’1-feb-02’);
Insert into salesorder values (6,7,’21-may-02’);

            Create table client(cno number(5),na varchar2(20),amt number(5));
Insert into client values(1,’prasad’,1200);
Insert into client values(2,’rajesh’,100);
Insert into client values(3,’suri’,200);
Insert into client values(4,’prakash’,2100);
Insert into client values(5,’kiran’,1000);
Insert into client values(6,’bhavani’,2000);
Insert into client values(7,’baba’,700);
1)Select * from salesorder where cno=
(select cno from client where na='baba');
2)Select * from salesorder where ono=
(select cno from client where na=’prasad’);

3)select * from vision where eno=(select eno from vision2
            where eno=(select eno from vision3 where sal=1000));

      4)insert into vision select * from vision2 where
         eno=(select eno from vision3 where sal=1000);
            5) create table vision1 as Select * from salesorder where cno=

              

(select cno from client where na='baba');

              

6) update client set amt=amt+100 where cno in (select cno from
                 salesorder where amt=100);
            7) delete from vision where eno in(select eno from vision2);

              

 

For
More Explanation
&
Online Classes

Contact Us:
+919885348743