Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

there is one requirement of the nested query is

the nested query should be declared into the paranthesis and it doesn't works with
the
order by clause

Que::

Write query to display name,age whose age is equal to student named 'ram' and marks
is greater than student named 'arjuna' from the table dummytable..
this is the example of nested query..

Ans::

STARTS FROM HERE {

SELECT NAME,AGE FROM DUMMYTABLE WHERE AGE=(SELECT AGE FROM DUMMYTABLE WHERE
NAME='RAM') AND
MARKS>(SELECT MARKS FROM DUMMYTABLE WHERE NAME='ARJUNA');

}//ENDS HERE

Que::

Write a query to display the dept_id of all the students from stu_dept table whose
usn in dummytable
is equal to usn in stu_dept table

this is also a part of the nested queries..

Ans::
we can write the queries in two types..

1.
select dept_id from stu_dept where usn in (select usn from dummytable);

2. this is not a sub-query (i.e. not a nested query..)


select dept_id from stu_dept,dummytable where stu_dept.usn = dummytable.usn;

in query no. 2 we have included the both tables of which the comparision is done in
the query
and the comparision is done in the way of calling the members of objects using
object name
where object name is here table name and the member name is here the field name is
'usn'...

You might also like