Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
day4

day4

Ratings: (0)|Views: 44|Likes:
Published by irraju

More info:

Published by: irraju on Sep 05, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/27/2010

pdf

text

original

 
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.
Edited by Foxit ReaderCopyright(C) by Foxit Software Company,2005-2007For Evaluation Only.
DAY4------------
OUTER JOIN:-------------------------IT SATISFIES EQUI CONDITION AND ALSO UNMATCHED DATA FROM ONE OF THE TBL;represented by a (+)signSELECT A.ENAME AS EMPLOYEES, B.ENAME AS MANAGERS FROM EMP A,EMP B WHEREA.MGR=B.EMPNO(+); ->LEFT JSELECT A.ENAME AS EMPLOYEES, B.ENAME AS MANAGERS FROM EMP A,EMP B WHEREB.EMPNO(+)=A.MGR;FULL OUTER JOIN:----------------------------SELECT * FROM EMP FULL OUTER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;satisfies equi condition and also unmarked data from both the tablesREPLACE , WITH KEYWORD FULL OUTER JOINREPLACE WHERE WITH ONif we want left/right outer join we useSELECT * FROM EMP RIGHT OUTER JOIN DEPTON EMP.DEPTNO=DEPT.DEPTNO;SUBQUERIES=============<----------------------------------------------------------------MQ---------------------------->(<-------------------------SQ------------------------------------>)IS PART OF MAIN QUERYIS ENCLOSED WITHIN BARACKETSGETS EXEC FRIST,RESULT IS FED TO THE MAIN AND THERBY THE MQ GETS EXEC.CAN B E INDEPENDENTLY EXEC AT TEH SQL PROMPT.MQ DEPENDS ON THE SQ.SELECT ENAME FORM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE ENAMA='JONES')CLASS ASSIGNMENT----------------------------------WRITE A QUERY TO DISPLAY THE II MAX SAL FROM EMP;SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN (SELECT MAX(SAL) FROM EMP); PUT THE +SIGN IN THE OPPSIDE OTHERWISE IT GIVES THECARTESIAN PRODUCTie. put + sign on where there are mentries
 
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.
 
Edited by Foxit ReaderCopyright(C) by Foxit Software Company,2005-2007For Evaluation Only.DISPLAY THE EMPLOPYNAME WHO IS GETTING THE SECOND MAXSALARY------------------------------------------------------SELECT ENAME,MAX(SAL) FROM EMP WHERE SAL NOT IN(SELECT MAX(SAL) FROM EMP);ORSELECT ENAME FROM EMP WHER SAL=(SELECT MAX(SAL) FROM EMP WHERE SAL<(SELECT MAX(SAL) FROM EMP));SELECT DISTINCT SAL FROM EMP X WHERE &N=(SELECT COUNT(DISTINCT SAL) FROM EMP Y WHERE X.SAL<=Y.SAL);TYPES:---------------RETURNING A SINGLE VALUERETURNING MULTIPLE VALUESMULTIPLE SQNESTED SQCORRELATED SQRETURNING A SINGLE VAUE-----------------------------------------SELECT ENAME FROM EMP WHERE SAL>(SELECT AVG(SAL) FROM EMP);RETURNING MULTIPLE VALUES:----------------------------------------------SELECT ENAME FROM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE DEPTNO=10); here subquery returns the multiple valuesso we use two kinds of solutions for thisSOLN: ANY,ALLSELECT ENAME FROM EMP WHERE SAL>ANY (SELECT SAL FROM EMP WHERE DEPTNO=10);ANY ACTS LIKE A "OR " AND ALLACTS LIKE "AND"SELECT ENAME,SAL FROM EMP WHERE SAL>ANY (SELECT SAL FROM EMP WHERE DEPTNO=10);MULTIPLE SUBQUERY------------------------------------<----------------------------MQ------------------------------------------------><--------------SQ1------------------>AND/OR<---------------------------------------->NESTED SUBQUERY:-----------------------------------<---------------------------------------------------MQ------------------------------>AND MANY SUB QUERIES FALLOW IT NESTED IN
 
Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.
Edited by Foxit ReaderCopyright(C) by Foxit Software Company,2005-2007For Evaluation Only.
 
WRITE A QUERY TO DISPLAY EMPLOY DETAILS WHOS SALARIES ARE GREATER THAN AVG SALARY AND DEPTNAME ACCOUNTINGUSING SUBQUERIESSELECT * FROM EMP WHERE(SELECT SAL FROM EMP WHERE SAL>(SELECT AVG(SAL) EMP WHERE DEPTNO IN (SELECT DEPTNO FROM DEPTWHERE DNAME='ACCOUNTING'));SOLUTIONSELECT E.*,DNAME FROM EMP E,DEPT WHERE SAL>(SELECT AVG(SAL) FROM EMP) ANDDNAME='ACCOUNTING' AND E.DEPTNO=DEPT.DEPTNO;OR IT CAN BE WRITTEN LIKE THISSELECT E.*,(SELECT DNAME FROM DEPT WHERE DNAME='ACCOUNTING') FROM EMP EWHRE SAL>(SELECT AVG(SAL) FROM EMP) AND DEPTNO=(SELECT DEPTNO FROM EMP WHERE DNAME='ACCOUNTING');SELECT ENAME FROM EMP WHERE SAL=(SELECT MAX(SAL) FROM EMPWHERE SAL<(SELECT MAX(SAL) FROM EMPWHERE SAL<(SELECT MAX(SAL) FROM EMPWHERE SAL<(SELECT MAX(SAL) FROM EMP)));CORRELATED SQ--------------------------------IS PART OF MAIN MQIS ENCLOSED WITHIN BRACKETSSQ AND MQ GETS EXECUTED CORRELATEDLYSQ CAN NOT BE INDEPENDENTLY EXEC AT THE SQL PROMPTSQ DEPENDS ON THE MQWRITE A QUERY TO DISPALY THE NTH MAX SAL FROM EMPWHERE N IS AN INPUT FROM THE USER
A2.97 mm

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->