We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Date: Pr
nq Records and
Joins in SQL
+. Gpoup By:-
; Guoup by
( abl nto
by cause w wsed bo divids du 4 2
psand we Can perfor SG funrdtions th ues
this cuateggagel chioly wll tuba,
groups: In
Sutput wach gpetaps: fer'eg > T) we rand sun of sale
olo{ ach cuupan tinct wehave de divide fable Kecodt
Bap No FlNows Zibb awe
$369 suet ——_clevk qap4
1494 Wien —_salepmuan
13a} dard Salesman
566 buss Mouoast
4654 Mhvkin Salomean
1698 blake Mannan
082 thok Maw
hes Stoth Baalyst
1.34
Pores
oh
Ling
1e Ay ‘We reann
—
=
Dote :
SELECT DeptNo , Swa(SAL) FROM emp
GROUP BY Deptno :
s4so. |
7450 l
Dept'No wn(SAL) |
20 ae
.| SELECT Job sua FRont =p aRour BY Jor.
a ‘
Towel | sum(SAU)]
Clak goo! “fa |
| Salusmen Beo0O
Manager $275 4 t
Analyst 300°
Pubs | 500° t
| SELECT agade Dept Alo aa op GRouP BY
DEPTNO,; 1A) [SELECT Tob) ound (Feb) FROM Rnp Gkour gy
a Sab: oa | wif
E : ob fount(Fob >] 9 |
Clerk
J Solumon [oI4 Cnr) fo DR
Manager |g
i AnalaSt | A. sol
ne a [Paaldat 7 l if
8) ECT woe (snt) fa from emp GROUP BYRDote:
De Tr oft
20 ytl
30 550
(o NULL |
@) | winks SQL commands #3 the follies basid on the
a tabletop:
oe...
To diapleny dt lowest ial in tach deparchanand -
| SELECT DEPTNo, MINGAL) FROM EMP.
.|G@RouP BY DEPT No.2
- | To displey Hu_no: of smplosyss in oe _Hepealirnt
| SELECT bEPTNo aE From: EMP.
Ic, 2OUP BY DEPTAey
Te display Abs yo: of swepleges andr 0c bariag eh
T SELECT MGR, Sux (MGR) FROM EMP
@koup BYOcte : _
To cep tle average tamamission job wit
SELECT 508, any Cethed) pais wp
HAVING with GikouP BY
fot
Tf we want to filter or rurluct some roues from Lh
output cud by GROUP BY thon we vse YUAVING
wo] clout. Tt is _wsecl to put wndition of AWS -
; as having Clause. we =_ appear ea
S| OOH ERE» utd: beare tte GROUP BY: With WHERE we
d ear DEPT. AVOrCSAL)EROM EMP.GROUP BY DEPT
HAVING: JOB AN (HEL SALES)s.
SELECT DEPT, MAX (SAL), Min CAL), COUNT (*) Geom EMP
GRouP BY DEPT HAVING: COUNT (*) >2Q:.
| SELECT DEPT, MAX (SAU), MINCSAL) FRom EMP. WHERE
“TeAL>=ao0o GRouPBY DEPT HAVING DEPT: (N.('IT) yR’):
q: Diffoortiak bls Wolube clause and haw ing claust +Date
HW.
Pq 535 (Type A) i Vila B
“(Type B)! Q 1-4, Ole
: Ya (ude Abe OL vAR
& | JOINS
Pisploying Dato ex Motiple Tables |
ol
Somebinu ds bwais Be Ho
from fiwo or more tablis which deyains thy
-joviing zt tuo oriwien tably + Sdoh» psy
“ein Gusny 0 Py !
‘LP MySQL » fame you 46 hand” Jatn
Tes tod Totis Saker Suis
um, CDate :
Cantisian Product (Cross Tain) ‘
No
doping ek wn of
3
dagptts, of Ana tao. slats
The eandinalily iy | Ba alti Pere
candivialitiis | se Ae wo» slehiond “
hides Teaehwn
0
Roll No. Name | oManks TName
0) Vivek) >} | qo, M¥: Govind
He Sudlakoh | 210 Ti | Ms. Suncita |
\04
Auf evo! | Degnie= 2 Gadinahity =a.
=3 Gadinolity=3
Result of Cartesian Foducl
KollNo Name "]Morles, |) TeNo | TName
toy fwvivele | Box | Tui sf: My. Gpwnd
HON Vivek. ao. | Tz pf) Ms. Sata
wl] era | Sudbakan [i gio! fs Tir [| My Govind
loz Gadrakor |} wy! fe | Te Ms Sunita
lot A &To Tu Myr Govind
vost Abi aro | Te | Mss Suita |
abtoafoe dard wil O oisbrcs Woo Jost . r
al Dewar a tacs {es [Sgatoxt-
Gina = 3X2» ei: SELECT * FROM: Studunt, Teacher >aoe
|< lequt Jo! 7 Jo
— 4 —| sr eQur gen Jon fy oranda ane facred on tha ey
TT condliten of ining Column Guana thea ‘Ted |
wabach i “common” co both z=)
ohne & a column
biGmeaall
a du Glow Fable ela Sita G
4 oe)
{Join column:Date ;
"3 Non -EQul Join ‘ 7 =a > eee
In Non Eipai Join, Keeoids ani pond: en Lu condihon
ottum. than tquol operater (>, ic > = >=, <=) fon
+ doining ' ‘Column Covictep in). Slam) ta veces Ft
M ath
Syntace See ¥ Fiore R/S. I
Cie whe ReS> Se, | a
A. Nabival (Tour!
The Fahl” jour is much “Similan to > Gui de Joan he
sucerds ane jomed bn thx sguality wndibon of
Joining Column except that Bavténimorn lusrn
appears one bearers inst t [
15
Syntax: Sela en Janie sea
whue. RO = 3 Cb { Jeci
EFFriar, <1] Emp — ENan 7
ay = Piailabh | Muvabes
Er | Shanuki | Doki * |:
E3 | Ayn | Mumba f
EMP E4 Kid Kapur
vy» i Puneet _ Gunnai
Ee |
bk - | 7 futon ayHorne Worle atte Leas Maus Posse od
10]
a Type A omy 249g Ge) eur Ge
sup formed by GROUP BY clauses 5
MMW aT
4h Ute vay Epa ia si
VA Vue :
WHERE wnditions aru applicabl._on individual ows
whvues HAVING wnditiow wu Opp licable oh goup a
AAKA VA Wy
Te groue BY clause combi all ‘thase sucords thot have
[idethcols valuss én) a particular Yield on a quoup of Feld
1 ‘cals v én) ap dani Hapa fp
WM AKS VS wary
Aggrugadts
oO arid
WON 2023 , |
or wk with data zl multiple sous of ok
ibis agypagedis vals ot SS
ag: sul) , woul, max)? o-’
dv i
Type B
: Y) SELECT MAXCERICE) FROM: BOOK. INFORMATION ;
@) SELECT STORE. 1D, SUMCSNLES_ AMOUNT )FROM
of SALES GROUP BY STORE. ID.» <6
NR S55
» | SELECT STORED wi(SALBS AMOUN FROPK SALE.
{GROUP -BY SRORE_ID HATING: SALES AMODNT > 5000 -
a) :2]
=
L)SELECT COUNT (DISTINCT STORE.’ ID.) FRO
STOREID; a
sane Hew aos aA? gntaen
e)Selecr AVG CEXAM.
GROUP BY EANIA_ 1D HAVING: EXAM-1D <1:
Dato : J i
7
iin
M SHE,
a) SELECT STORE. 1D, sum (9ALES_ AMOUNT) FROK
SALES WHEKE STORE
INS
io rn 625,45) GRouP BY
SORE) Fond MAM: RESULTS
: Ma 4 es BAB
¢) SELECT NT Eaee agen TsTULID)
“ [@)SELECT. * FROM EXAM: RESUTS Ww
fk
FROM EXAM RESULTS GROUP BY EXAM_ID:
2 MSE
HEREMA AME
Bassas ooh SOME cps
URE LEO an DER
{ r
Saag ys
A) IS
12: |)) SELECT Bepid, Copihr (#)AS: Frapiitney FROM rope
ORDER BY Depil a ‘t ployee
i) SELECT Naw FROM Bplay WHERE WAME LE
Wy’
1%
hii) ALTER. TABLES Salary \ADD iolé
BUA AA
(ake ars
any. ‘Petes: Sa FLOAT:Dote :
—_—
‘UPDATE - ‘Solony SET Total Sal = Beuied BOE HERE
Bonus; vaudae saa 1 we
SELECT MAX (Basic) FROM Salas) WIHERE: Bonus> 40;
ol [Max beast [ous 1450 as mony HGR
joone |
[oe [ost]
id
Lol
{los
af
Date : ee)
MySQL offen cfjoc wai by wleich y ee
joe bwo or name pee
Methad “t+ Vieng Maltplc tabli “with Feorle
SELECT * FROM EMP DEPT Where Exp DPB tpt
Sfpountty oe Haran
Tf common Column art
fo we Ou walified nam * ite
Method 2:- Using JOIN kuyusord
MySQL offs JOIN keyword which ab
cmp liment all Spe ¥ Join pode dd
SELECT * FRom EMP JOIN DEPT ON
Erte Emp. Dept No =Dept : Dept No ;
&
45
4 [Table Alvas
ly
A table alias ts a teporary label along eth,
tu tobl ramin FROM aha fe rDete :
for 4 ualifand namete Avid reg
SELECT _E-Deptrto Enains Drome ,
FROM Emp E Dept D <— _fempor labels & He
WHERE E- Deptno= b- Deptno; vd et
Te can be writlen using 1 table eas vstiad of
repialite tabu nanan rey tives 4 Sti e 4
Ext..| Find out dhe name of Employes. werking tn Produckon
Deptt - K “ald
SELECT -Ename Prom. EME, DEPT oHERE rae
Emp: Dept No = Dept- Dept No AND \DNawin = “Pro duclian :
of? EName ri aig pnd apc Lae.
Ariitabh 30 M3
Ani
&
fxg. | Find out theme loweso woyking th Same city
ae wo ba Tg | b tongs Green)Date =
SELECT Eran From Emp, Pept
WHERE emp. Dyt Nos byte Pp tie A pra fy lake.
t 3 Lty { 4 % 43
rey
OfPsI
Te Enamt padgade) contd 3. SAINI!
Araitabh )
Phoaukh | AS. pant aivisat Ss Sates
sish eo Home: Worke'y> 3 { 3
p
Bagley Bibel ship oypss olerg. is Baas
Cand loeation’*
SELECT E & Dept Neo, Locabian FROM hea
EMP DEPT, chine |
)
SELECT Enami. FRony EMP DEPT “sep
eat * DeptNe AND Onamt= ‘Pyoolu~
y PO
) [Display dulatly of wmployero along with Huix ~~
) te ee
Selct * From EMPE, ou thu E pile
5 D-Dept Nb
i) Display Sa names ters in Produckiys
dupartmert - 0
wo] Select Erarne Emp, Depk whirs ep. Ds 2
‘Jand Dawe = en ing why F
iti) Display the narnsland daynbso
waikiny co the “egy ha
Sdect Crom, Job from Bap Dept wolure Emp. Teh =
Pepe DiPtNo and cily = ‘Location’
iv) Pee tha decation as work aa city a pee
Mp the maa where docation and homunutr w
ze Cao, Becatida as eh Nah BS
from EMP E
“+ af Select Locotion, uty or SE a eas ind
’ . | benp Dept how Geeation I city +Date <
displ Wer dapardratnt nora Whit ‘no ample pr ats
weak, omen f &
Selecd Dnart peor Emp Dept Wher Enanu & null «
) Display Ha datas of pnd eae ecole in Mumba»
Scud * Jrom tmp pe whut ra 1a N= =k Dept No
| and Job= * mange e
+
sey dusignatiion were Hx total saliy drawse by Ha
employer 2
Saat jab, SumCpay) from EMP group by Yob ;
7 Bleck Cnamrddob ora €M [Bee beth to =
pep htyl ne; a e Ay
Oukpal
sit) [ En ame ca i). Work | Homutown
(eee Kan pus Dele
[awit | Engine J Kolkeko | Mumbai
Bone Mumbar
fon Hotel Unnnad Murberwn) | Snail Tb 7 -
Araitabl. Mane 50000
Shanutl Managyr 4000)
fe a f aaa ai * Bal