0% found this document useful (0 votes)
48 views2 pages

Important SQL Quaryes

This document contains SQL code examples demonstrating various SQL functions and techniques including DECODE, CASE, subqueries, correlated subqueries, inline views, REPLACE, TRANSLATE, NVL, and NVL2. It also shows how to select the top N salaries, avoid duplicate records, and delete duplicate records.

Uploaded by

leninapps33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Important SQL Quaryes

This document contains SQL code examples demonstrating various SQL functions and techniques including DECODE, CASE, subqueries, correlated subqueries, inline views, REPLACE, TRANSLATE, NVL, and NVL2. It also shows how to select the top N salaries, avoid duplicate records, and delete duplicate records.

Uploaded by

leninapps33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

VENKATESH.

C
SQL IMP
HOWTOUSETHEDECODEFUNCTION
==============================
>SELECTSAL,DECODE(SAL,3000,'HIGH',1250,'MAX','MIN')FROMEMP;
CASEISASTATEMENT8.1.6
=========================
SELECTSAL,CASESAL
WHEN5000THEN
'MAX'
WHEN2600THEN
'MEDI'
ELSE
'MIN'
END
FROMEMP

TODISPLAYTHENthRECORDS
=========================
1>selectmax(sal),levelfromempwherelevel=&salconnectbyprior
sal>salgroupbylevel;
2>SELECTDISTINCT(A.SAL)FROMEMPAWHERE&N=(SELECTCOUNT(DISTINCT
(B.SAL))FROMEMPBWHEREA.SAL<=B.SAL);
DISPLAYTHETOP5SALARIES
==========================
SELECTROWNUM,SALFROM(SELECTROWNUM,SALFROMEMPORDERBYSAL
DESC)WHEREROWNUM<=5
TOAVOIDTHEDUPLITRECORDS
==========================
1>selectdistinctinvoice_numfromap_invoices_all;

2>selectinvoice_numfromap_invoices_all
union
selectinvoice_numfromap_invoices_all;

3>selectinvoice_numfromap_invoices_allawhererowid=
(selectmax(rowid)fromap_invoices_allbwhere
a.invoice_num=b.invoice_num);
HOWTODELETETHEDUPLICATERECORDS
===================================
>DELETEFROMEMPMASTERAWHEREA.ROWID>(SELECTMIN(B.ROWID)FROM
EMPMASTERBWHEREA.EMPNO=B.EMPNO);
SUBQUERY
==========

9985319212

VENKATESH.C
SQL IMP
>SELECTENAMEFROMEMP
WHEREDEPTNO=(SELECTDEPTNOFROMEMP
WHEREENAME='SMITH');
CORRELATEDQUER
===============
>SELECTEMPNO,ENAMEFROMEMPA
WHERE1>(SELECTCOUNT(*)FROMEMPB
WHEREA.SAL<B.SAL)
INLINEVIEW
===========
SELECTDEPTNO,SALFROM(SELECTDEPTNO,SALFROMEMP)
REPLACE&TRANSLATE
===================
SELECTREPLACE('VENKATESH','VEN','SUN'),TRANSLATE('VENKATESH','EN','AB')
FROMDUAL;
OUTPUT

SUNKATESH,VABKATASH
NVLANDNVL2
============
SELECTNVL(COMM,2),NVL2(COMM,1,2)FROMEMP;

9985319212

You might also like