Professional Documents
Culture Documents
SQL Server Class Notes PDF
SQL Server Class Notes PDF
fom Emp ide Batepiiis (unr, itive) = toe
Nelo “Ralename and Patera firdions ome very simviay Lhe
ony abppownce fe bbe past one gies bho a as
Vowchay ond Seand me fe the Resufi 98 in
‘By Bae: “Fétexas an ‘integer Yeprsentig the oy of the
Month “op Bho spacipiaed fron “iake
SF Plat Daglecttatec)
Mowr(alate)- Fetuing ary iinkeger tok repeseata the month parl-
“Of a gpteipied ~ able
& Sibel Moth (Cat Balec))
Sr Select fiom Emp there Mohthcetredale) =O.
Yearcoale Feduans an YWlegey Ural reprerentis the tur pot
of the secfied ola 4
1 ei act year (GelPalec) = by
elect Yery Crysyig 6) 2
Y 1948
Fate” Year W939 Hoyee! eg ) ,Nore Athen we Enler the abe“ te rruge be Bihar ty
1m fod | yyy formal to Yryy 1 ovr, soled
Evptessriid dasteclate [ month. load): Filerns be last ay of Me.
oon tn Pe Special able
Fg select Kemgousral Gel Babee?) aos — 06-30
Aatrt Beant (Gee Babee) 15) Goth - 07-31
Select Cononty (Ge Date (), 18) Boil -12- 3
Gare orgfslalgpast, Startdhle, cndolaie) “Felung the count of the
Spectre able bandyiea accross Ue cpecipied shartolede
and 80:
Zetect Ralonipe (49, (12/25/900) God Balee!)
Setock Dako Comm li2/25/qao!y Cee Makee))
2 Whe a auery + fied the number of “peas gach 2mpieyee
'5 working fn He ctganidation
Sabet 9» fem Emp she Rote Dye (4), HieRole, Geceatecr)|
2c Emme Enagne, ob, Sal, Doleoirr (yy Hnesake, Get Polee)
a3 Serprity, fram emp
WB
1360
—> white a Suey to pt the Kak of Empioyecs bdorico.
few a
Gebel fram Emp where Bhbe Kier (yy, pobake, GebBakec) =32
“Darzaoo (chit, rembenelale)* “Fels a raaditetime vate by”
Galling an alewot lo Me pecipiod olde part of the Peibiod ble
24 ealed- Dated (del 168, Get Bate ¢)) Qo9-19-19 (Fob Aad
4° Sole Purekoo (0, 48, Bel Baers )
BOG AQ-25 13:03 ee ae
7ONT F RN FARTS (py munlh, day)! “Klos 0 ole value poy lie =
j ——. J
Speiped poy, rrenth aro! Saige. ~
Pace DatepRW pares (' Yean month jay, hour mbrul-e s beconols Miliseceres)
“Relais a colotime value por Lie Specigied chle and ttme a
“Tote peoupaers Chan minule, Secon, Factions: precision)
“Felina Q Lime vawwe pay the Speed time God with “the Speefna
“Prect gion
5: Solel pareprompaars (1918.07,)7)
gage Daremae FRONPURTS (1918, oF My 12, 50, 30, 00)
Bert Wnt FoMPARTS Ci1,5 3% 36,00,3) a
Saed> trie pRompAkrs (1,3) 36, 00,4) a
Sap -
“ i deate:
TE (Bapranen) Nob greater than (rot 180 Standard)
> ldvike a auey to get the Wek ef empinyecs earning
a Bales Greater than Se00
Sey
=== Beck * Evom Emp Where Sal 7 3e00
7
- Saleck * Fore MP Where Sal }< Boon Bee Seo
fees ‘ vibe
van tis wage the value “Goou can oldu be tanen toto
Consdavaltons
t< Equals! pe .
I> Equals <=
Coy peso OperwToRs Compand —operakors execute Some -
opedtion and ec an ovginad value do fe Yauk OF the =
Opedtion -
Aid Egaais
_ Sobbad: Eqs
Hoikypy 3
= Rivide Eqpols
ha Noto Eqata
ea updcke EMP Sek Sal+= 109 Where Eman = loot =
Lotieal opkrames: Legend) -opeators tet Fer the “both op.
Some condihion - Logo operators Fixe compauttian oprabocs
Yetuing a “Einiean dolakype ith a value op Thue, PALoE
SY ONE No Ne
80And: Felns le 7p both bootean apieasions dre Le
OR. “Rekurns Lue ff esther of the boo1ean Expression 18
“TRUE,
\poolean opevaalov
Not: “Raverees the wiue oF omy bhhey
Benacit FReluns true tf the opeiand 8 within a yarqe
com “Rauine bwe ip the opevand Ss Zopeai 40 bine oF
Vyeo time oF Expressions : vies
Felund byoe WE the operand rroithed & POF
Reins we fp BL Sub-auery contains OY =
Reluine Lye IF Seme op a Sat OF ExpreseionS
awe hue oy
Any + Beurng true TR OY OFF ro
of eupreasions
- ayo tue
CAN 2 -Relyina toe 1 Ow oF a Sek oF Compariuiont ove
“boo
> Wie « jo get Hea. ab of emplagpes OrPAE
Ach fe grap! With & Solon of YeED+
» gnd Gas= Pee
Si Sdleck a fom Emp Where Tob = \wonoget
> \dvke QO Que do get the Wh of Emprypo® ano ae
~ Sauieing 0, Salory terre trons oN 28th goheiman ab @ :
~ Sey. Sdeck 4 From Sep nese Sdl_>3800
~ > white @ Sucy the Wh of Empioyect wah
lev, , sranagey wet carouuph
Sa1- Sect x» From Emp Nhe Tab “cer onan og =
Tob + Wuanager’ or “ob oan
ond Je b lace
she. soln °3
. i i 3
Gdeck w From, erp Khe Tb IN (setenty reanage
81 Sanosepr )Sdect 4 fom emp Where Tob Nobin (eatestian, “pratident’ )
ton)
Select A Yom Emp where Tob <> ‘Salesman ind Yob<>
© president’
> Witte a Guey to geh the Wek oF Empnyecs Whose.
Ssolovies From B00 to S000:
deck -¥ Fav here Emp Where Salaal Benaeer 3000
ard Sa00 tol)
Saeck + from &mp Where gayr=2000 ond Sal<= S000
a
Nays: Bs!
Bi: Bel
ogercher Joves Nox and mip Spar values
igo fntn cindidevabionw.
Soleck 1 Rom €MP Where Nok sal<3o00 And wok Sa?
> 3000
—> Wike a auey to 9ee the Vek of Smpeyeos corning &
Salons Athol. 73 teasthon 2200 -
Ddack « From Emp Where Sal~< 3000
)
Saleck = Gam Emp here nor Saf >= 8600
> bavile a Guey to ge Hhe Wak op employer
namo shouts wth the chovocker “8
SaPlecieck < pam emp Lhere Lat (Eame, 1) < 'S! ™
: (oo heie face wa net ae
Spieck % From Emp Nheve Ename Uke lay? Jax
Saeck x Porn emp where Lopk (team (ena, n=8
(ov) a
gait x fiom mp where Hevien (Ermame) line “84
82
“Whose~ —Phvite a Bucy to Set a lst of Smpiapes udhore Cen
7% Smith ov smyth
Solr Select 2 Fon emp ‘Whote eamden ( Grame) = Soondeu (omit?
Sauda (ov)
ages SO! * Fron Srp chee Ename Uke Cem — Ub
Ge opeakor ckbeumines, Whether 0 Specific chavackey”
Skiing motches. a. Specified Polka -c4 paktesn Can
irctade voquisr chayedlers ind whdeord characters “Ouving
Plean —mabchsn way Chavockova must exacky mckcy
the choedleys Speetpiee| fo the 2p-chayodtor sbviog -
Howsver vitideard charactera con bo matched with
ont ts of the chovackey Sbt vaing #g
ra grants Me tone, opratel He 2
Cold Chtvackors mare the Une eferaro /
Fietibie than w8iog the equaltdend rel Spat (he)
skong Cornpori gion Opeaker’:
fs chy Shing of evo o Move character?
= § Any Ging le ehovactey -
0 ft Caley Gngie Choracey Specipied rege (tae)
ot Sct (Labede iJ:
iS) * Any Boge chavodtoy nok within tne
Nn
C aboser)
Bpocikied vange ( CAa-F) eF eet (
~> Witle a ay to ge the iat of Empinyecs
ukose name stares uth ony chatorker botweer
A-S
Sor Seleck 3% an emp where fname Uke fca-caig’
tov) . j
Seek From Emp Weeve Ename urclBacoce oye ”~>livile a Quer te ger the Mel oF Empioyee Whese.
mame doesdt ~Stoih otth Chosackera bekueen ang
Qe Select ¥ Prom emp Where Ename Nok ne" -91f.
Lov)
Select 4 From emp Where name Like \fAa-g] ag?
(oi) i
Seed: © Flom &mp where fname Line’ [Molders ]efe
lov)
Soed ¥ From tmp Where Ename Line ‘thea
Cet Ooemameg: SAL SEWER pave The Fovexting Seb
2, Dyson
oper Which Cormbines Yomulbs Yeo dese oy move eunesic >
fio a Snge yeguit Sek» “Whote are + -
— unten
— untonci)
= xnkovsect
- Except
“Te Cembtne ~the yesots of kao @uerfes 2 need +0
Bus the below basic ues:
1= “The tomber@nd” the order 6p-—Ehe_Cowrnn® matt be
Soe tn the Ot Spotless
2° The. dato. bypes eras be compolflo\e-
ste a Gey do find cub the Jobo assecialcd ih ~
clepioo ge % 30: 35
Seite alec Tel FYom
ges‘onion: Corrbines The veaults of dun oy move aucyies tbo
ce vwSulk seb, tho inctdies atl the yours
Gh
hak ¥ ber to an auevies fn Lhe wanton: eliminsticg
clupicakes :
UNJoN_ A? Same as unten luk duplicates nok lee
teefnakod
Sul Sdeck Tob From Emp where Repkno = Ro
a — UNION
Speck Toh from bmp where Sepia 8°
tov)
Tape = Lo
Sect Job From tmp hanes
Unio m any
Select Job From Emp theye fo eae
im Pacers FReluma ary Viskinck Yelues peer d
s retuned by both jhe auerios’ the lerk ac
_ vighe aides of Gnkeraeck —opevane”
ha of
~ Latiie 4 auony to fe the Common
7 leptons ao € 30.
en Seleck “Te Fim mp where qtr “eo
Envergect
Saeck Toh Pom emp uhere Dapkno= So
dhe. Jeg
“Reking ony sialic Notwws Fam
gueiy tb aya nob found of the vgn
Qe,
—> \bike
on ayy to get the pb? thak axe Specipte
ne 20 when coenperes with Repne SO
Veveepe:_ Sedecs ob Franny Emp Hhere Replno = ao
Execopl
Sdeck Tob fom Emp Uhere Rephno =30
Siting_ Concakenalton opevabove - ty += /
@, (uiike Q OUe} Ao Commant a Hine Hen® ‘pus Salory ne
4 Selec. Empne, “eid + Enarne + (yan Soiny ese"
Corwert (vorhov(i2?, Sen’) 3 Comment From Emp
Seheck Erepoo, Cred & Emame + Yo Bao 1 +
fornok (301, tel titan) @3 Commert Bom Emp
Crving “aiiag Nemes “1o_GEmrs tle can qe nti oe,
an eee Oo a rs)
Nawe 40 coon in the geek Heb tn
i gpevent eanys
=
Zax doc, Emeno, Ename, Sal 03 Galery fom Emp
orm EMP
Seieck Empno, Enarne, Salou = Sol F
pf aor)
CIANIBES* Ue can add these ao bo @ auory Foy
pasty. ackstueral ophana He ers » gpeoptng +
Cora eke Te
~ Wheve
= Step Ry
— trang,
~ ORDER hy
Laeres cipieS Oe Search, condition For the ows
Yehanedd by ane ery 88 Mok te ot e8htal
OM the Ghusttbed doko -
86fo
yay
p By: Used poy i ‘nko a Sek
of See yoos basing on the vows of me (or)
Poe Comme “t -
> Wvile a aucry +o pind oul the member OF employees
MeeiKing in the argarixalton:
Select “) fom emp &
f
~ Puke © Guey 4o ind dole the toto! number OF
~ et Ss spkeng be
pee eT Ao Zaeh department
a Selec: 4 cane Wom emp Group hy Beptno
(ov)
(etn Emp| Seteck- copno Erp count = Exsparke)
—davcet, prscey 7
. Form Emp Gap by
canny Aa
eee yr
+ |b
3 6 6 wo &
“IF we wre Grepay Ciopae in & Buery peak ae A
°n Me doh whi be dwided tro ctreient MPP “¢
OA tho Couumn Spectpied. in the Gapey exquse. one then
Ereakes the Gwop Ferdkion on Each croop Fo ger the
Yeats - ‘
—> Wie i tuey 40 get no OF- Empoyees per Each Job
So\A~ Seieck Teh, camk OH) Fam esp Groopey 7
cor)
Seieck, “Job, Empaunl » Count (=) From Emp Grup
Bor Emp-5
3 aye
a ae P yi
= Be 3 i, 3"
87lite Leng Groep & Cruze Ia a Grey» we need +o
-fevow coy) Consider “He foun
J+ When 0. §aup-finckion i appted on @ groop Sk vekurn®
omy a Binge vane but Each grop Can veluin &
Sepevalc Vole -
QR Uge graphy Clouse ny on @ Comme which Conkains
skipionta voles, rover appig Sh mM UNE Corns -
> Wile a @uey to get the. numba OF empiayee 8
samnirg tn gach job Per gach dopavtment-
Seleck dana, sh, Eerpenank = con®) prom Emp
Crop By Depkno, ‘Tol older by Depino
When we Gee malkipe coumne fn a Spe by Cravae
Risk, doko tn bbe take 19 divided ‘basing on me prval
Conran of- the mapey cine and then toch Yao ie
Eub-divided ban on the Second Conon ae a
Ssoupry cause ced then jhe Srosp punctian 19 SPP
B® Each inner or ste “ Tho Yeauit
| 5 orev bie0%
Erne — Is ej 7
—?
Cle
fo & Yianager —_—> _~+i/|
‘Proaidens ——> |
ao 7 CkrIX
S . y
6 Salesma y ———>
eters — >
do Manager '
A ao Solesman
= Bo hoil 6
Bo Clerk om
30 Mayagey !
- 30 Anoloye 3
3 Holl é
NOL Noy
89Cube operate Gerrakes a Simpe Group By agqegrabe
Yous, You ep Aggreqvale and cross= babuwakion Yous:
SE Stock cant ex) From Song
Sdleck Dekro-counk (8 From €,
rom emp G %
Select “Fely cour. ce) From Beng ant Job °
Wb counk- [From Emp Sup Gy Veginw, Tob ciety
_ By Aepino, Tob
Cov)
Syr Seleck Replng “Sob cunt Ua From 2mp Grop BY cake (Peping, Tob) :
Refo - |choatoyss| clerk wale | | a
e Te bk, doo
| ° t 1 ‘gal 8 3 |
a. .
2 2 : o | 5 | ¢|
ae
\ 3 bE i ° ° 6 |
i er —— +4
—B s_ | 3 | ais |
— lp - Anayie 3 :
Clevk 5
Mecagey &
‘Freaiderk 4
Salesman = 3
90- —sbhtle o Gaewy te get
ONpnizakion
ia
So}r-
dhe highest salany in bhe
Select thax Cgal) Fon emp
- Hike @, Guey to get the highest galaxy oF Sach de plates
Sor Select Rekoo wax. Caal) foe Eine Grp by Repro
PUvtle o sueiy 40 gind ouk the ‘nigneel sal oF Fach
.. ap , adam with the mame of the Smpoyee
Sor Botocl Bephoo,axtsasl, Enome from Emp Group By’
Reshan. AL Torti
Nobo :- “The abe sie usin ok be cxeantedl peas
While ust gpepey cious fn O stotoment i; e
Select luk" con corkatn OH nes things fo!
= Cowmns that ove aseoctaked with Group Sy dail
Qe Aaguocpote to) Grsp fanckion ®
3) Conslants
gunn ey Gu
“In ay above auery Enome seca fancy ‘ iL
the hice - 20, 4b cannot be wed 9 he sat
She Soke Sopkno, max Cea), Crane fom &mp ae 0
Jrvasid
Soke Depien, bav.csall, Gid-Sobke 6 fan Son Geaip By cep ino
D valid
Select Stein, Hh Man (sat, viens From Emp Gwup sy
depine 7 Tb Y yola.
91> like a Query to get the bola! fnyesbenent being mode
On Sallavie® Por an the Ermpnyers, For fach Sob and fel
Zech Job Qn -Lach depisstrne nt.
SOK Salock Peptno, Teh, tum(Sai) Fom Emp Groyp By Towop
(Rephno, Tob)-
—7 Witke & tuewy to gee fam the thee above as wal 4%
Tehwise frveskment aiso-
Sol- Seteok, Beptna, Tob, Sum(sas) Fron Srp Group %y Cube
(Seplno, Tob)
—> Uvike a Buoy sto gin} nk The 4otad romber 9p ckik8 |
the ongantzakion
Seys
Selock Coon () Flom @mp where cob = bier’
> bitte a wey soo Bind Gtk the number of Clea 19
Each department.
S814 Select BZount wd fem tmp Where Tob <\choye” Group 8Y
Veptno
> Uite—a. wory to Gels the _ number oF Empivyecs in
Eesh epariient ony. ff cans 1% Gyenkey than 5
1S Seleck Bepkne, Count Cx) Ftom Bmp where CankO > & G
By degre i Tpvatid
Saleck Resin, Coonkes) Bom tmp Crap By deptro
Hosting CounkC’) > 5
Sel
92kame, Clause “This louse 93 ase used fos vesbvicking-
a dala: Sask Be Where Clause-
The Aipperence lskasen Whee Clause and having ciawe
13,
# \threve crouse 43 used for reskicking the yeas ‘pee
Sieuping ond Howng Clouse 4s used far YesbNching
the v8 Gekey grouping -
i ted ith @ aggregate
* Ty tek 5
TE te vesbiicdion 19 asaociel ge there: We theca! |
Fanetion we cannot use Wheve col!
ute Novi only
joving clause “4
* hee clause can be used Par Tes bicHry
. eo used casth Gop Py
Where 98 loving oluse fa veed aleng
Clouse -fp Pilkey Cov) yoskvick & _GyooPs:
* be Cause Cannot ke appied «atthouk a grap by?
rc
Clow:
individual rue
“> Mhike a Query to Gnd oak the number oF Employees
Zach job omy ip the cunt 12 19s thon 5:
Soit- Garo Tob, connie) From tmp ube ean Aas
—— Grrovp 2g aes € Tob waving Count <5
~piatle a auery fo find aub the number oF olen TA
Each erent: ep Ah & 23 ateaber than J
cbpedeenen 2H P i Coun gleater
Ser- Setack cepina, Conk Fon Emp \hove Job= Sciex
Groop By adeping, Having depley count: (9) >1°
i
Select ckpine, Conkle) Fromernp
\Wheve Jeb < cert!
Group By dep!r?
Waving Cook l=) 93“Tobie — tthere——
Bo 2
ao 2
be clone Cry eoider Be
igen [lt | waters a)!
SS cok
cet we th
Cader by causes cb is used for Goiting the doko.
Either in agrending cof descending eidey U oF a Query
basing on apecipted lik of. Coluren@)-
(‘eos
Saiplows Order 24 < cotta [ease [etc ]
asending
oy ))
Eqs Q Le
q e Empne, Cname, Sal, comm, Reptno - From
amp aides Sat
Selec: Smo, Eaame, Sas, Gm, Feptne Prono
Fp older by sag Seac
Sekc. empne, Ename, cal, Comm, Sepkno PPM
mp whae Repeng =A0 order By 2a), Comm
Nokes:
When uz have mort pe Conmos 4p ovdey by
clause, the deka grab Geko ananged basing on its
Frat ooumn ond if ny dupicate values ta the
Frat comma Shor) i whi) take tho eopparks oF
Scand comm For -anangerenb ey €Be Second Cound
wit nok be used-
‘Seteck, Empnd , Ename, Sal, Comm, Depino From emp
here Pepine <
Orde ee . iM ° (hee om. eotumin
v By al, Comm 20 Sn oe % Stherig
re1a Se-
———
vader oveby Bi
bihen appyfeg the order ‘sy ciauge using the oppsek oplion
We con climtnake the rember of wws Fran the akarbing:
Yeond
Fat Select Empne Erame, gay Pom Emp eidley ty Sal oppaek 6 Pos
~ Skips pret 5 yewids in He veBolk
Fetey
“Bu ustna the felch we can Specify She ramber oF
{ vg sae
00% y yelin after the. oFFSet clause tg Prowessed
“P Seleck Empno, Ename, eat From Emp oicey by om) of pack
5 Fous Fetch Next 5 Rows only
= Gebs te ws fom 6-lo tn to Yelk SKIPPING pirat.
5B wos"
=f Cole Gmnpra, Ename SA! Pee Timp ovdey boy eal
ofpack © “ROWS Fach Nek 5 pens only.
=—Gaes the —frak 8 92s ofthe vesult-
SuB- Queries
OA Suey anetde Another euey $2 Known 28
Abe:
Dyharr- Seteck You might also like