You are on page 1of 114
ne ottributes of a : - eee i cee ee on aq: Database: Database ts o place ov medium ae manne” - ty stere the data “a a Tee and ko 3 ' Exonglt fy ce Shuts Deto Att lee ao : Properties ny ———Znavaa | MANCUY ' EID : « ane Se , R SALARY Ay pect GENER > rr ow AGE 503 : ent _sgpters) DBMS (Dotabese mane z DEMS isa Softwowe which %& Used ty motintotn ‘and eet the database Sof word Feccoy mn A Avthovikal on, path — — oo | QUERY LANG LAGE Dems Th datobabe we Ca, ~” re speredort Called opexostons . " cRuD Scanned with CamScanner Gc ge age < ~ CREATE /awseRT R- Reap/ RET RIeve uv - uppate | MODIFY p - peLete [DRep — Be pr\rs , we use QUERY hongooge to gntevack . or Commonicake with the datobate Peotuxes + security and outage —> DEMs provides two etove date. Sm the form of files. 3 Qa DRS we will ranageroent x stern) = Ropms (Relatfonal datobase mm te hich is used RpRMsS & @ Fe of =BRMS Softioare wo se. Ho stove the data tm ‘the form of tables ame ch Asecu Sor ic oa ae —— STRoCTURED = QUERY LANGUAGE RDBMS Qo RRs to Amkewack with the database we ue Sbructuxed avery lan, Ee a store evexyTHng fn “the form of Qn RpRems we d qd ables Relational medel “Pelotional model wot ear ws EF cupp. }—Jeppme Ri pi moded wil Any perms which follows a relatfonal beCome RpeMs- Scanned with CamScanner Tole + Tate ts a logical arvgantaction of dato Consicls of OWS and — Columns. : éoloma| Attributes Pre ds] Properties THe Ce 8s oo single unit pRsent to the teble of EF CODD! WA dota entered into a cen must be a Sle volueg dota. , 54 Ged) Y (volia} EID — EWAMME PHWs | [=O | Evame Lame pa pe je. [al 123,ur6) | v | = nod No | | | OA O fo | | pique]. —y |' | [RES | 3 use | oe ae Jo B 4 | . | a) | | is | Wad seas 2 Acteraing to EF Copp we cain Store ge tn multiple fables “needed 10 con estantish ox Ganection between multiple fables with he help of key attvilvtes B We will stowe | Wn the Do te | meta dato. “ Neto date. sy “he details about the data is known at mete data. od o | Propertter paTA | P| etme ame > rey | q ——> FORMAT =_____5-speq me i SI2e€ —> I sok - Metadata %& stored 3 aeeeeee < Meta dob. | Metotabl ond it ts ovte created: \EraGe ame] Format) ize | a MAGI | TPES tsoke | ao — 4. Te Velidate the data we have 2 steps ® assigning the dato ages = 1 - ©) Bt assignee Condtraings, ° t & tery ond Constraints ave gftonal Dota tyres orf eda | uaiienne a Deke yes aaa 8, . a Dato tyfe tc used +o determing the Pe of data ~ to Le steved in the porticulay memory locatfan. i ¢ = t- CHAR S 2. VARCHAR /VARCHARD. 3: DATE 4. NUMBER 5 SS. LARGE OBTECTS e LycHARACTER LARGE parecer € FRIWARY LARGE oBsCc7 € characters “HAR a . ts Geenocgea taeda , consist of alphabets Cana! end “a ai) or numbers {'5-9)} x or special oe CHE vse dete Scanned with CamScanner | Synton —_ ; to — eH ar (si2e)| CHAR (toy rn whenever we are | “the CHAR cbtatyte we must | mention the size. ey ae CHAR dota 4 we Can Shere 2000 characters > CHAR ee follows an fined ce 7 allocotin. 2 VARCHAR 7 - spear’ i VARCHAR datatype is also used te store “the Chavacters Consicts of alphabets (a-2? and “a-3’) or Nunbers ('0-9') 8¥ Special Sgrbels a 2S fA! eles [syotare: VARCHAR (S12 €) | FE vprcnar (1s) cece’ BETPLIIEC we must mentton the size othe values should be enclosed wlth a pay of sin codes 7 On VARCHAR , also we Gn steve 009 characters > VARCHAR dato “ye follows an variable Length memary allecokion. VARCHAR 2 :- VARCHAR Sc similar to VARCHAR. heve » We Can Stare ypts 4o00 Chavactexs Scanned with CamScanner DATE is a clade. type used to stove sate [syrkore DATE | TH ORACLE SQL, we have evo formas | or) ‘pp. MeN yyy’ oy ey ge 1. AAR 2031! be NUMBER +» NumRER ts a data ae used ty stove nomeric volves. syntax “NUMBER (Precistont vtseace)) | Re disions— Pyectston determines the number of ferbeg ox values that we want to stove Sooke ecole determiner the number of decimal paints | usttite the given precision, . ‘ a Pe) hy MUMBER (4s) On) NUMRER (2,4) 4 tle + AVY, oe ; F we —the defowlk vole fey scale & *‘o” * Ke a for precision ts aC age SLARGE oBsects ‘ y CHA CHARACTER LARGIE OBJECT (coe) :~ 2, TuARAacter LARGE OBJECT 4s used to stove Charo. cles, Pes, documents upto 4&8, the 4 ‘ y Bicory Lane aplect (Bre). Bie ty used to Stove the binewy val ves OF im, be papa, mpi, videst upto 4 GG. iz Constraints: SS Conbtraints %& a vule Ge +o a Column. ' ontique Q Not NULL 3 check &- PRimArRy Rey 5S. FoRiean key fount GUE COMSTRANT. : dupltct UMQVE Gratreaint is (ae ty avoid the dup Valves fnto the Golumn ov table 2. NOT NuLt Gratroint. NoTNULL % used to avotd nut falue In ~the table 2 CHECK Canstrofnt -_ CHECK Conttraint Te o extra valtdation given fs a Column usith Condttfen, the Conditfon % sattoPred , Value wib be accepted else Hole te -vefected 4. PRIMARY KEY. PRIMARY REY fs a Gnattveint used to ee wetavd unig? Prom “the o charectertatics of PMY TY" == tm Cgmbtnatfon of unique and net null J Prinnony Fey | Goustroint- \ here must be Om only on@ primary key in the table] 3 ee i Conn eaceept duplicates or “nvlls tn the tople. ow nto the column. YS. Fowelan HEY; Fougn Mey Ss a Gnstrotnt used to establish o Connection between the tables oy mutiple tables. Scanned with CamScanner Ryeign ot rest Jo vefev FE ad ow feign | %t shold beg Primos key. eS 2 Foreign Con accept null and duplicates. = we can hene move “than one foreign 7] Sh the table. & e Primary & -foreyo “4 - Dyimo~y seer = 7. Pk-Primery a tk- Ff a eG prgcc4 =y REET e pk “Eto “ew me [sae DN 1 i Byeyy ONAME Lac | e | PEUGA | Yoo |} Jo | 4 i 1 e ) 7. \ | DING A 25080 7 10 : 265 De le =~ 3 | MANGA | Boooo |) wth | | | : i ; Bo | be (2) e Ko NG 25000 |, oO | | | one itm) —+ t+Ht& CHILD TABLE -- ~""Tparest ARLE = he primony vey 1S Goverted od 0 Fowehan ke We uM Queog oven Stotements-— 7 yUles + Date Befination long ply a Doto Markipuledion Long veg? (prey 3B Transaction Contrs| Longuag (TeL) 4G Dota Control Longuage (pel) 5. Doto Query Language (par) BETA QUERY LaveuAae (D9y):- Der 1s sed to velvieve the data Lom the ao DAL has for statements 7 ore, 9 StLect D PROTECTION DY SELECTION CLT U PPP PPP) y TOuns SELECT * : = erect CLAUSE 1S usec to select the Columns ol and aply ef ba a —— a Scanned with CamScanner Bwueuy Cdddd d é & uv lay eouuwTs eu Id d dd b Bhovddads PROIECTION -. ae tc oo Process of yetyteving “the date S Sele oy a rrtr”~—”—“=EECSS values present fn The Column wT be dtsplaged near : SELECT 3¢/ [orsriner] column. Name [Expression (Atrag FROM Table _ Name; Order of execution: 1. FROM 2 SeLlecT Write a Query +0 Atspl employee nome ond solony Dwrite oo oe to display solery and Commision of arnployes- | Duvite oo Quervt to ay clepaxtment names present Tn depawtment oble Y write 0 Avery fo a department name, Locobien, @nd department number: Ai ve 9 write o oy to Aepleg employee neme and hephex dake: y secect ENAME, SAL gselect ENAME sHacatrel FRM EMps FROM EMP; Y Select sar, cs FROM EMP; Q secrecy DNAME ERM OFT) Bcclecy OC , PERT No Ge). seLecr « pRem DEPT, Coe Penn, Scanned with CamScanner Employee table ». — Rowip lemprs| EnAme | To |e AREDATE [SAL + cn [bern null | oo 1400 19 §o-12-(F $0000 \ |436q | smitH | cLerk oe | 7369] smTH | cerk ste ater tone nuit | 20 : iia 3B | 1494 ALLEN SALESMAN 1698, i ore 28/000 08 | 200: oo 30 [ass Coe [sAvesrman Biel oyna 0 | 00-08 | Js | TONES Iraawnceee sepals alco | iE _— [smesriny soe 1qgl-o9- 281250: 0 | (woo 00 zo | | | wt BLAKE | maniager [18 37 |l98!=ar-el Qsorco nev 30) | & | t7g2] CLARE mange e24 a8hobot Sece-e8 nul 10 | 4 | 118¢) SOTT | Aeatisr 66 (982 Hid 0 so nv -- | wo 7827 KG [PResisEay nt 1881- ps os) nel tte | 4 a 4339, 7TVRNER [eavegnaal-16%8 frat 04 ef Low - oon «2 | in 78 ue ADATAS a | Ee [Bare a8 boc] ieee eee : 12 (1400) James | CLERK | 1698 (ngi-i9 03 e000 nu jae ‘ [ty 4 402 FeRD ANALYST 71 66 (481-12-63 % oo" 00! nuit 0 é rg | 1934] Rac names ae foes ane ww) 46 : pment dabele- » © owl berths onnte| ree ; i. 10 Acton wu “york : 7 2 40 sensente DALLAS ‘ [3 | 30 | SALES [crtcA@s ‘é aaa qo opeRAnns Basten | ‘ Scanned with CamScanner Ywrite oo aveg + top ai ian name and sal. SELECT — EWAME, SAL FROM MP; [ewe mer: Tr = | ' | smith [genes | | 2 | SMITH 80:00 | \ | | ; j ALLEN | thoo-00 | 4 | WARD ooo | i. | Tenes | 2975-00 6 | marqin | 12-50-09 | | | jis | BLAKE | 28c009 | & | clARK DLYSD-00. | % | | | Scott 300000 : J mG | coop. a “TORNER (ovo n \ ADAMS | (100.00 a ty IT ; eee Booed { mittee tBo0.00 Dwyite 2 ave em pleyee j to atepley salery and Commission SELECT SAL, Comm _From emp; | RowiD | cAL \ $00.00 Boo-6 0 1609 :00 | 12F6 0d | eres | 19 90-00 nwArcwr ra of | ' - | [Rew] cAL orne4 | [Rowid SAL [Coome com | al + | D8 Gog AVI LB AD 00. /NUK nol | & Neca! null Sosesee f muy Zoo'04 9 | R000+08) NeW ae 180020) ny} fas Eo | Qc) | null Ate |} To: 90 | 000 114 08°00. 24 Wa0:s0| null Scanned with CamScanner Bwvite av ney to sspley department name present So departm ent tole: SELELT DBNAME FRM, DEPT) Rowid | DNAME | i { | AceousTING | | 2 pestARtH 3 | SALES os |__ DpERA TIONS name, (ocokiOn Owe 09 guey to epi cup artment ond — deportmeht number SELECT DwWAME, Loc ,DEPT Wo (om) SELECT + FRM Depry feet Bee DEP TNO Dname | Lec | Rowid | | ' [wm | AcCowtinGe | NEw YORK | > | | ResearcH DALLAS | [ | Bo | SALES | enicags (og _loperatons | Boston | 9 “ a wey to eae Result of Result of] my || EtO) Ename sav WHERE cLAue ——-SELEcTtanll | \ 200 | =F oo CLAUSE DINGA a080 | E_PINGLA 2000 |= 2. y i =—'l. | : a Fils | mane | sco chp TANGA B00! 2-277 2 atlas) oh ee FH! oa | WANG! | 2500) [2 MANGI 3500) 3=2 F cst 1A = lu | pase [secs |G DIT 2080| 4>2F a Lao 4 Resvik oF FROM CLALSE Ls 2) FROM ciAust starts execution, | pLL 3 7 will eH Y-Re Th of FROM eLAUSE Ts ge to the database and gearsth for the table and pot thot table under execution, be execoled ERE cLAUSE exe Cot eA ous be voto. | 33 ffter the execution Of Rot elAUse, WHERE clAUSE | Scanned with CamScanner SwhERE cidAuse yeturns bylean gutpot ke, “true ow false. D WERE cLAuse ts Used to filter the wecords: 4) Adcey the execution of wheRe cLAUSE , SELECT clAuse wi be exe coted PP Pw te cespormible ts prepore ox gener WHERE — EMPAD = 7839 oR | MOR HIREDATE SAL tt Deg Ne &) SELECT clAust : the vedoit table 7 gure o Que te sploy “the employee details where 7 EmPWO is 783%. a SELCCt he FRM EMP 7 & e Row | Empyo — ENAME ‘ 71834 KING | PRESIDENT = Null 19BI-N-E See 06 nu\t EXD, whay tpn , DEPT No SELECT ‘ m EMPA fo S= Brite om Rueny to aispley ENAME who So woking at WO: J0 a setect AEnAme = = FROM EMP = WHERE DEPTNO10 5 a |gowid ERAFAE = 4 CLARK 5 2 wa . 2 MILLER ~ | PRoyection: - : | AQTD names of a the emplyees- =| SELECT ENAME Ll From emp ha WwAaTD nome and Gmmision wven tp ON the emplayecs et 5 BE NAME , COMM > select 1 FROIN eps - 1 pert Po of All the employee ee EMP table. : I e . : FRe Scanned with CamScanner www wvvvuVvuUuHeueuuuunwue ww =e ew ee wow ou WAO TD me NAME Ond Jog of all The — SELECT NAME , 30K FRM Emp: WAQTD AM NAME, TOR. and SALARY qiven at the eropley eet: SELECT ENAINE, JoB, SAL FRO SELECT 2) write who's s F WHERE ENAME= ‘SMITH F DY wesite are X write ore wwonleins y write wrote pwr’ noms wor Kin wo emp; ton a oi t nom eee as © dicplo ANwuAL SALARY of The 7 ELECT SAL 1D Rom EMP Or od bo ateploy nome of the ompaby ees who clerk: SELECT ENAME FROM EMP WHERE JoB= crerk’s oa quey aopley salery os SALESMAN: of thé emplyees wsho Sevect SAL FRom EMP WHERE OB = a weed to display ‘than 9000 serect ¥ From EMP CUHERE Shee a ower to cteplay detoils of the qs Jones. | serect * ror erp rac =‘ a wrere ENA TONES ; re Scanned with CamScanner ‘SALESMAN’; detotls of the Emp whe Cans emp whose | GQ wvke a query to ey details of tha -EMp who wos hired e attey e4-TAN- al. SELECT eo FROM emp WHERE WRedATE > Of - JAN- al; Dite a wey to aspleg nome and solar ole with his ANNUAL SALARY . Sf The Annual SALARY %& more than 12.000 + SELECT ENAME, SAL, SAL KIL FRom EMP WHERE SAL*# 12 > 12600; Yuvte a yor to chopley EMPNO of The. empley ees who | ave working in pept 20 SELECT EMPNO FROIN EMP WHERE PEPTNO= 305 g write a quesy to lisp’ ENAME and HIREDATE 7) ave WIRED before 1981, SELECT ENAINE, HIREDATE FROM ep ' WHERE HIREDATE 2 Shere a meat ‘31-DEc-8) > lo) WAQTD details of the EMP warking ad MANAGER | erect FRorm EMP WHERE TOR = MANAGER | y wad TO NAME & SAL ge to an employ ce if employee goxns w Commission of wupesh Yoo. Select CNAME, SAL FRom EMP WwHERE Comm = 1400; 12) wAgTD details of Emp having Commission more thay 4 an Liky ' i a Scanned with CamScanner ae 22 e2HHanhnhOOVDOOOO PRE bP hh IP SESE EERE EE SESE eee ea REESE tere Oper SEE SELECT FROM erp i WHERE adi: comme SAL; 1D waar empro of emp WRED be SELECT EMPNO FRom emp : WHERE HIREDATE 4@#'3]-pEC-8t ) fore he ( &4 owed detoils oF Emp ey ak on ANALYST Serer teccsatee FROM emp WHERE JoR = “anacsr’ 1) Wa 7 oe fe of emp cortny ee SELECT 2e FRO Erp WHERE SALS 2000, Logico\ operators :_ nse ae | AND fs a. binary opevator which will toke te Tap and 7 o boolean. output Syrebol * ae ee RK operetor oR %& & beary operator hich will take ~tog fnpets and re Oo" boalean output: Scanned with CamScanner Ps. “Truthtonte eal AT B | Res * | oY | 7 e VG 1 Eat a FoF kL Not opevat: vo = wilt Loko HoT %& a unary operator which Sopot and (pee a one butpot rep eee q Ee © Le @ Le L DIsTIWeT © 1 Ju plte _ . _...., dopltater Srom “the Columo- To the first ox ments we Con pass ong nomber eLnuse€ - Lt. on an ah Lt Lt Lt et SELECT CLAUSE, DISTINCT CLAUSE u the 4 of Columns after % 9% she prsTInNeT ® a SELECT DISTINCT TNAME .SAL From emp / Resuik e ‘evo | cont | Sar ENAINE) sal . JE19 | 200 a pe | v | 7 200 — 2 ae 2 \ | | B | Yoo* o od a Yoo . | 3 word | 4 s \ Yoo | | igg | 40 | ica Scanned with CamScanner WAQTD “he di¢rerent coloriet of emp ay 2es SELECT DISTINCT SAL FREI EMP; SELECT DistiINcT Jo, DepINe FRM Emp; PRESIDENT to “CLERK lo SALESMAN Bo “ARALY ST to MAN AGeR Qo MANAGER 1d CLERK Bo \ CLERK 20 \ ExPRessioN Any statement (ane oo wehuit tale we ailll Coll %t aA EXPRESSION: 5 ppevator & sai OPERANDS LscotumNn _ NAME Ls Lirer, LATERALS + a a ,,rt—r.._C«aC .rsCsiézsC:aCS y the user. we hove 3 4yPet of Liverats : g y CHARACTER LITERAL Case Y PATE LITERAL senaitive 3 SomBeR LITERAL Scanned with CamScanner ALIAS). ALIAS fs oa alternative nome ge oo ee eapression, yx we wil use AS Keg userd 4o write the ALIAS name but % Snot Mon dator! . Hy We Con unite the ALIAS name with the help of or—“_i—O™COCOCOCOCOCssis*sCt# ex yr mordole vn J SELECT SAL ‘As) 2 (AS) AWNUAL_SAL OR NAWaUAL eat” FRoM emp; write a quey to cteplog “the annual salovies of the employees: with ALIAS SELECT SAL % \2 As ANMuAL-SAL FROM emp; . WABTO Dil the tompley 22 details okey with the annual {oble f SELECT seve , SALYIZ "“Aunual SAL” FROM EMP s Operators io SOL‘ - | ARITHEMATIC operaToRS (4+, —, %, 1) 2. CONCATINATION 6PERATOR !- (1) > COMPARISON OPERATORS :-( =, Ja yy ES) he RELATIONAL OPERATOR 2. (5 2 . oS Ss. SPECIAL OPERATOR :_ (4.0 RQ oT IN B BETWEEN 4 NOT BETWEEN Sis 6. TS NoT LIK: i Sf LIKE Scanned with CamScanner na nHOHHOHOODOOHOOPHPOPUOEP 6 suBOvERY speRATDRE y- (4+ ALL = 2. AMY M 2 EXISTS > 4. NOT exists) 9 GACATINATION OPERATOR - 3 CONCATINATION OPERATOR ts used to Join the steps. 7 % a WS ewarne > ES > SPecta OPERATORS: HS operator oe |. ee led peetOn cule ll Coke 2S = Nelue tn Lang ond multiple voluet wm RHrs: <3 Syntax + Column name/expression TN (V4, yo, Vo)? | See ane = ce = & a SELECT 4% = FRom &MP ep WHERE DEPTNO rrh{ 10,20, 39) ; — st Ai 7 A” kero 3 ie es : N l0,20/ 36) 20 IN (1) 26,38) a) lozlo 2o=\6 F > \p=30 ay or 26 T ly ieee WoO=z0 F | 3 =< 2A Lileretion 7h pitevotion 3 \o NW (10,20) 36) 30 IN (0,20, 30) <3 (oe) ee Bozlo F Yor 2s . 20220 =F { T 3 Jor ae F 20 =20 7 2 WAQTD ‘the engleyen detodls who ove worktg Sy ? Deptno 19, 20,20, 40- 7 setect x FROM =P WHERE DEPTHO TN (8,20, 30, 49) 5 a Scanned with CamScanner WAND the emply et name and SAL tho are cookin ce MANAGER ey SALESMAN % DEPTHO fb 0 30, SELECT €NAME, SAL FRem emp WHERE FB pul manner’ op, salesman) AND Deprelt ronan WARTD Employee mame and Hivedate @arning SAL moe than Boos e and veorling 4 AwALYST oR CLERK: a @ SELECT ENAME, WIREDATE e FROM EMP e@ WHERE ow INC’ ANALYST’, 'eLeRk) AND SAL > 3000} e Not rN operrotor :_ e NoT IN & stwiler 42 EN operator Tnsteod of selecting Aa the reCovds tk will wefeck the wecords. - [Syatex: column name/expresson Not In (V4, va, +... vn e eet neta tate eet —— 2 | al WAATD the emplayer detolle except the emplayeet canrking tp > cept ns lo or 22. e SELECT & Froth

(nomes stoxt wi y) Ssh! pptrames having 's') ‘ys' so tnomes end with ‘6) “pest! + erames have Consecutive '') . Ca success) Sse eu tc a WHERE ENAIME Like 4g? oe Sey eu Sh 4 —sgname he tl vir : ¢ 7! ACE 24 charpeter is '/ ~~ --- theme having sib cheaters} ‘ fs 7 joslpome having 94 letter Peon (ast ne t's @ 9 ee ° J LIKE: NoT Like % similar to Like operator tasted ot | selecting the vetords HM wit elect the records. grtext column. name /erPression WoT LIKE "Pattern sc mokch | = a Di + SELECT * FROM €MP ' vvyYV YUU UUOUHUUUWUUUCUKOHHE wheee ename wo LIKE ‘sk? Questions on opewakors'- Dd Lisk all the comply 44 whose — CommisPan fg nul: ; select ¥ , Fron EMP WHERE comm TS NULL; 3) List out he employees Wh dork howe a REPIRTING MANAGER 1 (nee): sevect * ; FRM ECP ' wiere Ma FS MULTE Scanned with CamScanner R Bist aw the SALESMAN iin DEpt 30. serecy e FRM CMP S* WHERE wBs ‘salesman! AND cept plo cnt (a) 5 e - SOR TAC CALC IMA D Dusb at the SALESMAN 3 Deprno 30 AND HAVING e Soleny grote” then S00 a SELECT ee FRM erie re WHERE —JoR=' cALECMAN' ALO DEPTH TAN (20) And SAL >I, Teh “Sey bepye stn) e SList ast the employees whose Name tarts with ‘eo! os ‘A, @ SELECT x FRM emp a rd ,@ WHERE EWAME LIKE "3.1 oR ua? camene LIKE ‘at's 7 ae an the employees except those who ore workin in DePE lo Ray. da e REtecT #4 ]e FROM Emp e WHERE Deptno tloT XN (lo, 20)} e ylise the ompeyers whose name does pet stort with 's!, @ SELECT # e FRom €MP WHERE €NAME NoT LIKE Seip? , e Dist on the employees who are havin & d REPARTIWG MAMAGIERS Ty HEPT lo. < Soe. ae ‘ FRom €rmp WHERE MGR x5 WoT WOLL ABD DEPTNO sw (10)s ' F tsk ON the he whose — Commission ite ol ; one) OA cLepk d serecy & , FROM EMP wheRE DeR= ‘CLERK’ AND COMM Ts NULL; W)List aut the employe Who dont have go REPORING, MaNAGeR mi peptwd jo oR 30. A Scanned with CamScanner Se gg eRe a - SELECT ¥ 2 FROM evip = yoneRe MGR Is Qull AUD pEPTNO TN (10,30); 7 WES on the soletmon fn dept 26 with 'ay—pec- 198!) HOIsplay al the employee who oe JoPmed in FER SELECT © FROM EMP pine Lh ReRe fh! ' , ‘ WHERE HIREDATE A A AEAN BEARD Be ECB) (e) WIRGDATE LIke, '~ nF ly) ow dy List the” umpleyees ‘Loho axe nA iuevking of ManAGreR and CLERKS IN DEPT wo and 2 with a selofy tn The 7 of AcOd ¥O 3000. eevect * Fro’ EMP WHERE SB Not In (IMAWAGER oF 'CLERE AND SAL BETWEEN 1600 AND 3000) p>) List The empleyed® whose solavy oT IN the en. of loo to 200 AND | in DEPT © fp, 30 oR 3d except an SALESMAN 1) AND DEPTNO TN (10) 20) select ¥ FROM €rfy WHERE SALARY WOT Be Tuten }008 AWD 2000 AND DEPTNO IN (10,20, 30) AND JOB NOT IN ‘saresinan's ip list the department romes whith axe having letter ‘9’ 3, hsSy locgtiong ah well as thir elepartin ent Momes SELECT YONAME FRM DEPT WHERE Loc LIKE No’ AND PNAME LIKE Ifoef!; 2D oieploy oul the employ ees whose Jt has string aa LLOOPPP PPP PPP POOR LUO eee 2 SELECT ¥ FRoM €nP : WHERE FoR LIKE 'PMAN') 5 40h who owe btred after Rr and ee "SELECT > arn ernP o een Sed-dan~83' AWD ‘3t-Dee~ gs! y ) UY © fe | ay st the ample © € BET WP 1962" An MPEDATE S tole TAN ~ 1997 wuere HIREDAT Scanned with CamScanner eee ere ereerri eerie: Ee employers Kived In Novembe, . Ond december. ce SELECT 2 2 FRom emp WH = ERE HIREDATE LiKE Yeniovel' oR RIREDATE LIKE '/DEcoh' 3 29 S 2H Ust on pe emnplyee names and Commision fy These. . amy 2 P logees who earn Comméss’od mere Than -~tery sole SELECT 3E NAME, Comm ¢ FRo SD WHERE Conn a TS NOT youll ~ND BAL COMM > CALS 29 wage Reus cole mene 3 : Pame and destanation By all the ample ees Vin for tin ‘ 3 d yep 4 eager and aldo theiy names Stortin Suet er dg > SELECT ENAIME, oR 2 FRomM €mp WHERE mae is NoT NULL AUD ENAME LIKE ‘ep cf! 5 u eg SIWARTH roma ord Solar of all the emplegces i thely | DS Anwar salary ends with »!, 2 SELECT ENAME, SAL , SAL™ 12 As Annval_saL 2 FROM EMP WHERE sare Like (0; 977 WAQTD name of The ee 7 atleast 2t's iy his name 9 SELECT * a FRom oe : ‘) | 9 WHERE ENAME LIKE en ? ay waQTO nome of The ompliyeca has name start with 2 a "Vowel 3 serect * 7A) ) pRoM EMP . art y he OR me Like ‘Ab’ oR EWAME LIKE E ‘i where ENA sane UKE ‘or oe ENAINE Like ‘pp’ oR & ‘ » euame LIKE ‘ah Scanned with CamScanner 2 Y \ Ser Eyactions Function Is oa block of Code oy set of programs to be Processed and exetuted. [ Buier Tu ps WGIE Row FUNCTIONS + “SINGLE RoW FuNcTigds:- FAVLTI Row FUNCTIONS SINGLE Row FUNCTION will take ‘hi’ number of Inputs user defined tunttfons Funteons and Processed tk and gives ‘x’ number of outputs. | ie SREO lp ' | ' 2 rk a ts i - ou ( LevalHc) WP a) ‘ ewan %-— ip SELECT EMAME LENG TH{EWAme) LENAME| smith fd : [sent [~ ponec | Bee Ge wre) ~ p< Moltt Row Funttron :- MuLTl RoW FUNCTION wil, toke ‘N' number of inputs ( 4 4 Combined tk % one Shot and processed * and Cc aq ‘ 4 Single output sip RFU ' | i ele ; ay ls ia : ‘ S ae 4 VAANCSAL) SELECT MAX(SAL) sae deo FRE lp : FRem Emp: Boo | = we. To ( neo S00,|/ hl Seo rere axe S MUITIRowW Functions 2h MAKC) 2 PW 2 suml) Qe AYE) 5. Countt) Scanned with CamScanner MAAR) Moe TY Row FUNCTION % od used to find the Maximum PYeSent % the Column, m WO PAIND MULTE Roud FUNCTION %e used +o fing the minimum volue Present 2m The Column, Sum). SUMLD MULT) Row FouctioN % used to find the telat > Sum of volved Present in the Column, AVGL) 1. AVG) PAULTI Row FuNctisN Ye used do Lad the over woke Gf oll the valve pe]esent 8n the Column. Coun TOS COUNT MULTL Row FUNCTION %s oced to Pind the Number of volved present fo the Column, Roles te uce MULTI Row Func tiorl Ywhenevev we ave using MRES In SELECT CLAUSE We sheong not use Calymo name olong uth the MRF, Dwe must ond Shovid pass on onguement 45 the MRE jel only one exqvment 3) we Cannot Sse MRF ‘in WHERE cLAUSE. y MRF Sqneves WULL: | 9 Countt> is the only MRE which uilt toke Aestric Cx) ses onqument: | Pinar the navel of any i of emplyees unity os % SALESMAN: > > > > > > 3 3 3 3 3 3 3 ? 3 3 4 SELECT N&(sAY) f FRM EMP WHERE JoB>'sALESMAN' ¥ WARTD th MAX ad rn solony of emplay ees eho vr 4 aaaking 0 cere fo Depron, ww Scanned with CamScanner 1 vue ——— Sevecy MAX(SAL , prine (Sav) FROM tmp were Jon: ‘creek’ AND DEPTNO THs (28) ; WAQTD +the SUM ot salary of employees who Kred dovin the te sen) d i : d SELECT suMmlSAL) FROM cmp WHERE HIREDATE BETWEEN WARTD The ro: of erp eeitce f ‘od “AnALyst! Awd Dept no tw(2o,%) 5 a WARTD the no. of -erople eC6 and max solo wkose aa vonged fromm Yycoo to S080. P f of empleyees qj 7) SELECT CoUNTOK) » TAAX (SAD = FRM MP e WHERE eal BETWEEN 4000 AHP S000; ~ b waar D the no of employ eos 89 each depowtment: ~ SELECT CounT(*) depen? a From Erp ; eRoup BY DEPWO) Scanned with CamScanner C EE Eieerrtrrtrtteeeeeeteme GrReup BY cLAuse:— i” . ds. GRour BY clause ig used to Gan the veloras tox : fo etteet peri gror so FROM toble _ name | [Were efritex_ Condition 3] — ae Column _ > name feapressien 3 ORdey of exccation:. I-FRor Q- WHERE (if use) [Row ~ By Row] 3- GRoup By (Row-@y- Row] W- SELECT [GReup-By~ GReupl - SGRoup BY crAuse execubeh Rew by Rew a, Lausy Any cause whith executea after Tes grrr “ clause uN execute the group 4 ror: ‘e ey -yoHe: enecution of WHERE cLAust, GRouP ws Adter the ciAuse ill be executed. 2 will pass Columns aS an By CLAUSE , WE —> Bn GiROLP anquement ' rh Columns whith we ave Passing 4% GRouP By — et CLAUSE we Con write that coluemne “fo select ctauce. Oy os ake oo wey © aipley Nor of employees ong to write b ny eoth departm ent . SELECT counT(#), DEPTNG FROM =P GRoup BY DIPTNo;: vo a ae 2 = =. E. = : Ra. ) Scanned with CamScanner DATABASE Resvit of GROUP BY wee ee ee eee eee cLAvse -a nl a) Result of my 0 j | Srith 280-20) , ot 20 RING WING, Sco ds ~ ADAY\ ~ \ Bo : ; 7 - - Ia MILLER Btop 30) | \ Scanned with CamScanner d % wu eeu vo vVVOUUOUOOBOKOKHKEKOEKOUIUUUUe Queries on @Roup By einustl :. IWARTD — nvmbey of emphyets workheg tn eath department except PRESIDENT. SELECT Count [¥) FRom Emp ‘ WHERE Jo@ not tu (PREAIDEWT') 5 YwARTD total a7. needed to pay atl the empl ecA in tach fob, SELECT Sum(SAL) , JOB FRom EMP GRoup BY ToB 5 a DWwWAQtD pombey of empleyent woking os Cena ita) each department . SELECT CoounTL*) , DEP TNO FROM €m were “Sd = ‘manacer’ ROUP By CEPTNO) BPwARtID AVG ‘olay needed to p aN the employees th each department Vexclu ding he” emplayeas of Deptno do SeLect AVGISAL), PEPTNS Prom tM WHERE Peta oT EN (20) GRoup BY DEPTNOS J WAQTD Numbey of employe ca having character Wa, “thety homes ” Cath Sob. . SELECT CounTl¥), JOR FROM EMP wrere enone Like ‘-h Ab GRoup PY TOR; GWARTD umber of employees - and og Saag needed ty poy the emplyert who sale in pyester than mace tn dept: aad 7 SELECT Count (2) , AVG (SAL) FROM EMP WHERE SAL 2000 GRouP By DEPT, YwAITY total salary needed to pay and number of salesmans 9 each dept. d a Scanned with CamScanner SELECT suIMlsAL), Count CaeB) 0) Conn (7 FRom EMP WHERE -soB =! cates An! 9 GRoup By Dept NO; PwAMTD Humber of employ ees ustth Ther mar'inom salaries neath Sob. SELECT Cgunt (4), MAX(SAL) , THR FROM emp GRoup By T6B; FWAOTD Max salavieh given ty an employee working eoth dept: ( d q SELECT MAX(SAL) FROM EMP ; GRovp By BEPTKO) 9 wadtp sof ti 4 Novof times the shavied have been repeated An emPleyen table. SELECT CousT(¥ )-1 Sat FRom emp GRovup By SAL 3 u WARTS nurbex of 7 HIRED on the Some oT ints The Same depowtment SELECT COUNT(*) | HREDATE, DEPT wo FRom emp GRouPp BY HIREDATE , DEPTNO ; PPPOE P OH OG @ e& a = e a! e | 'Qwhgto number of empl : ploy ees eat the came sale Sp the seme Hepastm ent SELECT COUNTC#), DEBSTHO ) SAL PRON EMP GiRoup BY SAL, DEP TH} WY WAGTD number of employees aie the Same nome Co cane depootinent : SELECT COUNT» ENAME , Heprase PRem Emp GRoup BY ENAME » DEPT No, WY WAQTD Number of empl oe ae the same Solow Sn the Some. depostment and seal the Same name. SELECT CounT(¥4) ,ENAME , SAL, DEPTN? PRE erp GRoup BY ENAME, SAL, DEPTNOD I 'J wadtp Number of employ ces (7 the Seme salar an the same departm ent and hived or the Som : SELECT coowTC#) —ineDATE, DEPT NO, SAL FROM EMP esp! GROVE BY HIREDATE, DEPTNO, SAL; HAVING clause « HAVING clause ts used -to Fitter the i SELECT Tore by — erpresston /qrour— function FROM table name \ (wrere fy crause whith erecuter ofter Group BY claus will Cexecute GROUP BY GiRoup. ‘Scanned with CamScanner ‘7 es In eath department . at} SELECT CounT(#) , pwo HAVING. CousT (*) > FROM emp GRoup BY DAO WAR TD Number of employees in each department ot leost thawe Should be 9 empl ax ~~ eee eee ewww © Result o¢ Cama D> FReM clause ~ Batabare Resott of GRovp By eat 4 CLAUSE MeN Reselt orf ta atte eae Eno | ENAMIE —9 __ SeLECT | | CLAUSE | 4 ALLEN oe CLAUSE | ALLEN Bore TL | sare 73000 S KeMG ame tol Coun TO) | Deve | B Towles 2000 10 | | | JES 2.000 | Sone | : ae Sy 2 |» joi | DZ SMITH 000 20) oo \ | = | TALLER | 2800 | iN S@TT see 29] 2 | 20 6 | KING | 000 | — ci YS WIUERast0 85] Lee F Scanned with CamScanner ~~ w~ue~wu~ueueecéées WAQTD the number of erplyees wonky Yo eoth deport ment uth maximum ealar 6000 SELECT Count (4), DEPT Ho FRM emp GRovp By DEpTNo WARTD ty HAVING tAX(sAL) = 6000 5 - lary gett number of employees ond minivnum Sev 7 @ d An €ath Sob atleakt there should be 9 SsALesmAN. SELECT CounTl*), ToB , MIS (SAL) FReMm emp WHERE JoR = 'saLesmaAn' GRoup ey TOR HAVING — ftbategies) COUNT (ed) >= 2: WAOTD dno and nomber of Emp wortiog fn @ach dept T4 Ttheyv€ are otleodt 9 eb€RKS In each Dept. SELECT CounT(*), BNO FRom emp WHERE JoR Tw ('cterk!) GROUP By “ExBDEPTLO Waving Count CH > =2 5 WAOTD Dno Ond total salory needed to Pay al] EMP In ath Dept there are atleast 4 Emp in each Dept SELECT —sum(SAL), DEPT NO, CouNTLY) FRom emp G@Roup BY DEPTNO | HAVING CouNTI) >= 4) WARD number of EMP Corning sal mere than 1206 tn 3800 5 Scanned with CamScanner WARTD DEPTNO and number of EMP wey only if there Ove 3 EMP working tn Gach dept as MAMHGER, SELECT — CounTl*), DEPTNO FRorA emp WHERE oR tw 0 MANAGER!) GRoup By PEPTNd Haw countl%) = 9» WARTD gq ee eae OM SAC oe emp tn eal Gok ete noe Sol eaceeds ogos, SELECT oR ,MAX(SAL) , Coun TL) FR emp WHERE_SAL>r.660) acta By TOR: é NING SHAY (SAL) >2600 3 wAOTD the solortoe whith ave eared ae be SELECT gat ,CounTEX) = ' FRom emp GRovp BY SAL 5 re HAVING countOal 5 fhe HIREDATE whith are duplicated in emp toble. SELECT — CounTUP) HIREDATE FROM emp GRoup By HIREDATE HAVING, CoumTl4)> I ; WEATD AVG salary of each dept Wf AvacAL ts lecs 2000- SELECT Aver (SAL), DEPT NO FROM EMP WHERE Aaiixteruncaseo GROUP BY DEPTNO; HAVING AVE ISAL) 2 2000 WwABTID DEPTINO “fF there ave atteodt who's name hed CHAR IA’ og SELECT CounT(*], DEpTNe FRoM emp , wonere ENAMe LIKE LA). og CHAME Like pg)! GRovue By pePtwo 2 EMP in each dept Scanned with CamScanner waetD rane HAYIRG cover) >=35 AND MAx salaries of cath Job if min sal 4s "OYE Than lo00 and mar “Sal is 12s than cooa. SELECT rATM(SAL ) MAXISAL), ToR FROM erp ' GRoup ey TOR HAVING MIN[SAL) > 1006 AND MAaslSAb Dnnev Query oY subaue, enevotes o vedult oF output 1 thot wesult will be fetched a6 a input to the outer ' ery, ry will 15 8B oking the input Prom aa ont wey w execute Coropletely and qe oa nal vesolt. Hence , we con ctote thet outer wey % dependent — ' on mer | ow Sub wey: why Where fer case 5! Whenever hove Unknowns or Andre’ date Yin “the | or i 5 fies: gusition at thot Hime WS ge fer cub were QMITH. Ex wagTDd ename cooing SAL move thon Scanned with CamScanner ee eee aaa > SELECT ENAME FRot\ emp WHERE sAL> (SELECT sal FRom emp WHERE ENAINE = 'sratcre!) ¢ WWAATD dome of he exrpleg SELECT ENAME FRM emp WHERE SAL > (SELECT From ep [sn Tei) ewam€) sAd Bn| Vy Aven | 2000 | lo | | | ina B08 20 | 2 2 tone | 200) 39 | a | a Jones | ase /to KING | a0 | 20 _ es Cay more than ADAMS sAL WHERE EnAmet =) Apams') > YWARTD home ond solo ef the empbyees conning less Thon 4 : SELECT wae, SAL FRor Emp wweRE sAL< (select SAL DWAHTD nome FROM emP , wheRE ENAME co) RING Jy Ane deptno of the Ya The came pept as zones. SELECT ENAME, DEPT NO FRM EMP WHERE DEPTNO = (SELECT DEpTAO IWAQTD name FRor employ (SELECT SAL FROM EMP where -ewant = 'ALLENY) 3 AsSigneni y WAQTD EVAME ond SALARY of all the empleyecs whe are Coorg move than milley But less than atten. SELECT GNAME, SAL FRoM Emp WHERE sAL> (SELECT SAL FROM EMP wHERe enAme - 'mitter’) AND sate (SELECT SAL FRoM empP WHERE CNAME ='ALLEN')S \DwadTD ai the detotl: of the employees worlking tn Dept 2 ond working in the some designation gy seiry BELECT 7 From EMP WHERE DEPTH = 20 Amp JowR = (SELECT S88 ROM MPP \ WHERE EWAME = \srlTH ); 19 wagt? an the detaile of -the emple yee working 4 TIANAGER She Some DEPT ab TURNER: OHMOOHOHHDODORDHAAMHA AMAR @ om in elect ero eMP ok: ANAGER! Avp CEPTNOS (SELECT DeprNno WHERE FROM EMR whERE ERAMME = !ToR WEA) é L ——_— Scanned with CamScanner 'DwAOTD NAME and piREDATE of the employes HIRED o-Pter 1986 Sond before. kIWG, SELECT -ENATIE, HIREDATE FRomM erp ; i - WHERE HIREDATE >‘at -DeEC-19%0 AND = HiRepAte < (serect HIREDATE y FROM CMP where ename = ' Kina’); PIDWARTD Nome and sAL olong with Aunual sAL -fy all ie > whos sat is less than BWake ond move “than. 3r0o> : SELECT ENAMYE, SAL, 2A, ¥12 As \AdNUAL SAL! > FROM emp > WHERE SAL>2S00 AND SAL <(SELECT SAL - Fiver, Emp ? WHERE ENAME = BLAKE!) ; => '9 be ar i 9 'Y wAQTD the details o¢ aes who €2xnN more theo 5 sCoTT But less than King, > SELECT - FRM emp = wngre SAL>(SELECT SAL > FROM e&MpP ' wert ename=scort') AND sal ec (SELECT SAL 9 FROM EMP WHERE EwAmMe= ' RING!) 1) WAQTD NAME pf the employees whet name gtorts with 4! 3 fwo wows fo he Some Dept al BLAKE ui ecLecT ENAME FROM EMP an ename LIKE TA Au ab ab _ WHERE - peprn « (SELECT DEPTNO = FROM emp i 3 were ename = 'BLAKE) Scanned with CamScanner (2 wAQTD NAME and comm if employ ees Carn Cormssion Ond @ WORK rw “The Sam DESTGINATON OA SAI TH: eo SELECT EWArMe, Corar’ ~ FROM Crp WAERE coma Is NoT NULL AND TOR =(selecT Jor FROM Erp WH ERE ewarne = ‘mer! a. a, QwWARTD ottails of an tha empfoyeos working as cLORk J oo the Soma dept oA TURNER. @ SELECT ea FROM Emp 2 WHERE oR = SEER? AND PepTwo= (ELECT HePres e FRor) ip e WHERE ENAMED 'Tyeyee! e | oy) WARTD EWAMME, SAL AWD PES\GNATION of. “the emp AwnuAL SALARY is move “than stnltH And — We those less than king, SELECT ENAME, SAL, TOR e From trp e WHERE SAL* 12> (SELECT SAL ¥ Ip. e FRoM cmp e WHERE ENAME = Sanity 4 AND SALE Lees FROM emp (SELECT SAL x Jy . . WHERE — EWAINE s Mewes ail 3 © tote a BGT AMG oe conn : +hon one Column, select moe @& lin, cy the COOP Columns weed nat 4.5 « SO dotatypes of thse has ty te Same me, bul the @ Cose 2. « aN + 4 whenever the dete te be selected ond the Condit ‘ do pe executed ove Present %, AEC O9 end dition ¢ tables we use Sub Query: ¢ — Scanned with CamScanner & erp bea ey SO "y ei | ewame | cau [ peprwo DEPT (eter eit DEPTNO | laa (4 ALLEN 20 IDEptNo | OWAME | Loc | -—1-— 4 ~ area pe | {> BLAKE 2000 oI Ae een uy i . we | 4 fems ed] Abarm's Dsoo | to “dd dsddddd PT “WAQTD Lec of the ADAMS. SELECT Loe FRoM Dept WHERE Dept Nd = (SELECT Deprno FRM Erp WHERE EWaMe = ADAMS')} ! uv @ 2 WAATD names o¢ the Cire ly oon tagvetag ecient SELECT euame d Ge by? FRoA emp WHERE DEPTNO = (SELECT DEPT NO q FRovA DEPT = WHERE Loc: 'ts!)> = 2 wAQt : 3 AQTD number og employ cen Lookin to dept Dee => SELECT Count (¥) 7 3 FROM Emp 3 WHERE DEPTNO 2 (SELECT DEP TWO oe FRom Dept o WHERE DNAME =O); a, YDWAQTD ENAME sal of ol to emp! Atlee lye Corning mere ‘thon Scott ond oe 1 dept 20, 7 a SELECT ENAPME SAL = FRom emp 3 WRERE DEPTNO =96 3 AND SAL> (SELECT SAL 4 FReM emp ~ WHere ewame='scoTr ys = Scanned with CamScanner SWARTD ox the details of the empl a fo the dapt oa. We toorking ak SELECT FROM emp WHERE TOR: 'MANAGER AND DEPTHO = (SELECT DEPTNO FROM DEPT : : WHERE DNAME? ‘ACCOUNTING J} © c e = eo S-WAQTE al the details pt the em ployess exorking 9 = = © in & the Some dextg ro on os MILLER and works tH Lecaction i > e e new yorlk SELECT & FROM Emp WHERE yoR= (SELECT JoR | FRom EMP =) WHERE ENAMES 'MILLERDAND | é DEPTHo= (SELECT DEP TNO a FRorA DEPT “I WHERE Lec= ‘weur York) e P PWAATD number of empley eos eek? ea a cewek ty the some cdeptno as smirH and a, Mere “than king Syed ofter MARTIN tn the Locetish BasteN: SELECT Covut(#) PRM Crp WHERE TOB= CLERK’ AND DEPTNG = (SELECT Bepraig FROM Emp “WHERE EWAME® ‘sotiri!) Aw sAL> (SELECT sat FROM EMP WHERE ENAMES king! Awd HIREDATE > (SELECT HIREDATE FROM €rap WHERE Ewame c marry?) Scanned with CamScanner > AND peptwo = (select DEPTNe FRoM Dept 1 Ye wHere Locs 'Boston) 3 DWARTD maximum soley qe fo a person working in DALLAS ¢ SELECT MAXISAL) FROM emp WHERE DepTnd (SELECT DEPTNG FRoM pepT 1 wales where toc 'parras') Tye of SUB- QuERy - I SINGLE Row Sue Query 2 MULTI Row sua query wv G@CUbCdE wee " SWWOLE Row sue -queey Bt the cub wery returns exnctly 1 wetord [valve we coll it ~ ww OS single wow sub qvery. d wed > Bf He veturns only 4 valve then we Con use. THe normal | 1 bperetors Ox the special operators +o Compare “th volves. gy Bosgrp dinome of ALLEN: SELECT DNAME FRoM bepT WHERE DEPT NO = (secect DEPTNO FROM erap WHERE EWAMIE= 'ALLEy _Emp ew | enan€ [SAL | peprno| __ ‘DEPT t | ALLEN (000 | 2 } [Derrwe | DNAME aa oe BLAKE 9600 10 lo | DI | ui 3a | clark | 200 | % *” ol = \ 20 Oi | tel 4 MILLER | 1560 lo eee © | smith | 2x00] to Scanned with CamScanner Notey y Qn ingle vow sub query We Con Use normal operators a dy special operators: SMYLTI Row sv Qvery:- Qs the sh query returns move Than 4 retord/value we call f ak put Row Sub Suery Be tt veturns move than 4 valve than we Cannot ese the normal opevotors we have to use only specie! operates to Compare the Volues- Moke - : See AP FHiCuIE bo Identhfy whether a quer belo: Bogle ow multi vow so, it ts ‘always eCommended to use Special ppevators to Compare the values WAQTD dnames of ALLEN and SMITH. SELECT DNAME FROM DEPT wHere DEPTNO [Ej sevect DepTNo zw / PRM EMP ~ 1 WHERE ENAME TN ¢ ALLEN”, ‘emery !)) » Rev®, since the sub | query xeturns 2 rWéords | we Cannot use ‘=’ Op | we've t use IN op. | ename and solery of the ie Canin, of dept fo. more WAgTD ead than empbys®! of SN enAame | SAL | DEPTNO | a PRAAHHAATOHRAPITAVVINIP EST TTIVYD BD 1 | Auten | to | 20 | gare | 2000) 10 | 2 3 | etARE | 2000 | = i (enter | 00 | to | eo) le f sMitH | #00 | _| SELECT ENAME, cAL FRoM emp i WHERE sal[>\(serect SAL / Rem emp 3 WHERE DEPTNO =I0) + , Hey we Cannet use our , we Cannet use s symbol te Compare roultiple values We Conlt : OS@ TN oy Not TN as welt becouse it te used o | 3 ov = and |= symbels: | | > Therefore we have to use Sub jue eve! Spaeeet| . ey Relational operotors such at (> 4, >=, 25). > - Eo esas e Sub suey operators *- DF WALL operator s- = Dt ig cpectol operator used 7 with a velational @ operator (m/e, >=, e>) 49 Compare th values present % ot the Rus. r AW opevotor yetuins Gut all eak-the volves at 2 tha = RKHS howe eaticfired the Condition. 3 of angt> Employ & nome and sAt of emplogeda aia, @ rove than all the employees of ceptno lo. > Lark \ 9 SELECT BNAINE, SAL 9 From =mP 3 wrerg SAL > ALL (SELECT SAL FRoM emp 9 WHERE PEPTRID =!0) 5 9 sty . et 1_tlevafintang s ALL (2000 , \$00 , 8500) 3 /- ia VEE) toast z 1500 loos > [S00 I S 4800 looo > 2500 F Scanned with CamScanner 2000 > ALL (2000 , 1sd0 , 200) 2000 >2000 F 2000 S 1500 7 Ce 2000 S200 F ewation: 200 > ALL (2000, 1809, 2500) Boos2e00 T 7) Boos 1500 TO | 2000 +2500 u uth Herotton + : tS00> ALL (2000, 1500, 2600) IS00%2000 F IS.0>1500 F { i (1890 > 2x00 & & evaction + 2500 > ALL (2000, 1600 , 2Sd0) 2500 > 2000 T 200 > 1800 “F 2600 >2500 F Y AMY 9 ator s- Zt is spectat operator used along with a velatisnas } opewotoy (>, 2, >=, 22) te Compare the values prescrt at the RHS- Any vperotor xekurns true %€ oe oF “he valves ot the pHs heave sottcfPed the Undition. ~ WATE employer mame. ond salary of she employees corning move thany eit ‘nM Dept to. Select ENAME, SAL res er oe a (SELECT SAL whe . FROM emp WHERE DEPTNO=W) ; w ia Ta Scanned with CamScanner AVMVDODODPP PRI eeeerenananns 1% «@ eee OOHUCHGCPCCECEC EEE r ray ————_—_——_—_—__—_———_- Sf Hevetfon: (b00>ANY (2009, 1x00 ,2 S00) 1000 > 2200 -F 100g > 1960 FF aH loco 59.00 F, 2__ihexatian: 9.007 ANY (2000, 1500, 9S) g0c0 > 2000 F Qo00 > Is00 FY T 2200 > 2500 F one 3__tevedion: 2009 > Any (2000 11500, 2560) 3000 > 2000 T see's Vee 7 j T ot Boo S 2600 T IS00> ANY (2000 , 1$00,2.500) 180 > 2000 F 1800 >1S00 [F j -F (S00 >2800 F 2500 > ANY(2O00 , 100, 280) 2500 > 2000 rsoo7ISOO + T 2800 > 286d F NAME | sAL | DEPTNO ALLEN 10020 BLAKE 3000 |b CLARK | 000 Bo mineR | 1800 10 ADAMS 250d 20 DwAgTD macrimuna slog of an ompliges SELECT MAX(SAY) FROM Emp; Scanned with CamScanner y Lei nam unM = Q.WAGTD name of he emphyse (0 = Solow: fp nia 2 SELECT earne » MAXUSAL) FRoM Emp; > ® Rim SELECT -ENAME FRoM €mip * WHERE cAL = MAXLSAL) 5 SELECT ENAME FRoM =p : WHERE SAL = (SELECT maMaA(sAd / FROM emp) ; _ Pwagrp name and solo earned 4 the employee - getty minimum solary. _ SELECT ENAME, SAL - FRoM EMP a WHERE SAL= (SELECT rain (sAU) ez ae) FRor\ erp) ; eS J NESTED suB-query: a vorttt ingl A sub wor written Tnefde a sub wey te known ay Nest€d cub eC e we Con nest about occ sub queries. x DwASTD ne oat qiven to an employee SELECT MAX(sAL) ¢ SAL FROM EMP; “| $220 » wAaTD second maim un eae] en te 2. empby | sae serect mMAx(sAY OY soe FROM EMP rant ) RE SAL (SELECT MAR(SAL WHE Ss FRom Emp)+ Scanned with CamScanner (JAAR eee © JWaAQtD 374 moocaimu solery SELECT Maxteat) FRomM emp WHERE SAL2 (SELECT ax tsad) a FROM EMP WHERE SAL < (SELECT TAX (AD . FRomM EVP) 3 > DWAQTD YF wactmum solo. > SELECT MaAxGsAD 3 Fre TAY 3 orn EMP Ea 3 WRERE SAL < (SELECT mAx(SAL) ) y From emp i WHERE SAL CLSELECT MAX(SAD ” FRom Emp 1 a WHERE “sAL< (SELECT maxtsAt) 3 DWATOH FF inimon — salary From Emp))); 3 SELECT MIN(SAL) ¢ 3 FRomM “Emp 3 WHERE sSAL> (SELECT MIN(SAL) 3 FRom emp WHERE SAL > (SELECT MAIN (SAD) 3 9 i FRom emp )) ; | 2 WAQTD Dept name of the emple 22 qettn a | g Salony: 7 SELECT DNAINE 5 FROM CEPT WHERE PEPTNO= (SELECT DEPTNO 3 FRoM emp 2 WHERE SAL = (SELECT Min (SAL) > FROM emp » WHERE SAL>(SELECT MIN(SAY) : FROM EmpP))): 9 Note: 3 | MaximuM | max % r rawr | min | > |} Scanned with CamScanner om NWEETED sub DWAdTD 24 minimum solv : SELECT MywlsAl) e a FRomM

(SELECT Min (SAL) e : FROM EMP) ; an DWARTD sth moximum ealory- . a SELECT MAX(SAL) Pa a FROM emp of WHERE SAL< (SELECT MAx(sAU) ol FRom emp ~ WHERE sAL¢ (SELECT MAX (SAD, al FRom Emp oa WHERE sALe (SELECT MAX(SAL) aay a a WHERE SALdSeLECT es CAL) FI eo a DWAdTD name sf the ef ployee. Ren erp) earring ard cin \ SELECT ENAME @ m Soy FRom Emp WRERE SAL §i(SELECT MAX (SAL) From emp WHERE mmBetsAL < (SELECT MAX(SAL) FRom emp WHERE SAL < (Select MAX Gav) Ro » Y wABTD EMPWO of the eroplay es ou Bi ™Ermp))y > ° Salary, 2 pnaotimcey ; seeder ErnPN6 "FRM EMP ne SAL Ga(SELECT max (SAD FRom Emp WHERE SAL < (SELECT MAX(SAY FRom emp) 5 5) wAQTD capavtment Nome of an rece 7 g y™ maximun soley. aeeangnqyre “a oo ———————— x — SELECT DNAMIME ~ FROM Dept DB WHERE DEPTNomA(SELECT DEPTNO 3 FRoM EVP 7 WHERE SAL IN (SELECT MAx(SAL) Yy FROM emp 3 WHERE SAL < (SELECT MAACSAL) 3 FROM emp WHERE SAL< rd (SELECT MAX (SAL) > FROM Emp? 3 ae WHERE s AL < (ELECT mAN'SAD) WAOTO aetotls of the FRom em 7 empl ce. ho wor hve d SOD 3 SELECT 5 FRom emp 3 WHERE HIREDATE ay (SELECT MIN (HIREDATE) FROM emp = WHERE HIREDATE > (SELECT MIN(HIREDATE) 4 Py FROM EMP); wAOTD 3 ® name of the empla ce hived before the fast 3 em plo 4 SELECT ENAME > = FROM Emp cc WHERE HIREDATE XW (sELECT MAX(HIREDATE) 9 FRoM €rpP a WHERE WIREDATE < (SELECT MAXCHIREDATE) 7 MwAOTD Loc of the employee who was ren EMP); a ¢ ved Rivet, geLect LOC 7 FROM DEPT 3 WHERE BEPTNO =(SELECT DEPTAS - FRom Mp d WHERE HIREDATE = (SELECT min (HIREDATE) 7 FRom emp); 5 VwAdtD getoils of me empleyee corning AT minimum 9 Salow. Scanned with CamScanner SELECT # ak FRom emp a WHERE SAL Ai (SELECT MINGAL) e a From emp WHERE SAL>(SELECT Pls) e 2 Sint emp ‘ 2 WHERE SAL > (SELECT SAl Fier emp 7 a WHERE ¢aL> (SELECT parucsat) : 2 FRom Erp. ¥ WHERE saL> (SELECT MIN/SAL) From Emp WHERE SAL> erect priw(sAt) FRor\ Emp WHERE SAL S— (seLect pw(cay FRor Empy)) 9. warp Duame F oF employee ay and SELECT pRAME maximum Sef FROM DEPT WHERE BEptwo au (SELECT Deptno FRom emp WHERE SAL “IW (SELECT MAx(sAD) FRor @rap WHERE SAL @ (select MArsat), : TEngphoye® AMD MAWAGER geLaTION - BD | Guar | mer | (| Aes 3 | 2 | sonitH \ | a | -sames 2 | Meas | Cosel Lind the rye portin manager ov a il " ey. YWAATD name Of Alen’s mon “eeLecy GNAME md eRe EMP ov (select mew wrere &t FRM emp sei) WHERE ENAME = ‘ALLEN; aes fai free elo FFs ero oP a a Pa Scanned with CamScanner

You might also like