Professional Documents
Culture Documents
SQL Notes Joins
SQL Notes Joins
SQL Notes Joins
T iGuse to Retnieve he
tecbles detu fonom mutiple
glmultumously
OCARTEGIAN JoLn)
ToLn eRoss Tai
TunER Toi Eouggon
LEET oUER Ton
(2)RLceHT OUTER Toun
FuLL OUTER Tol)
|4NATURAL ToLN
SELE TOLn
Columm maMe
SELECT GELECT Columm mume
Ponom table 1 CRoss fableg ; Tnam toibie 1tuble g
Ermp DEPT
E1D EndAmE Lac
16
oSTTHogo--
ALEn
Da L3
SELECT *
Reslt tohle
ETn EnlAmE
GnTTH lo
SooTTH 20 90 Da
Dgla
ALEN
AllEn Daade
3
lo
10 30
J+ Rs use to obtuin
the medching Retnencla
Gyntux AnlsT
SELECT
FRom
Column-numexo
Tablencme1JndER Toun Table mume 9
oN <Jain, Conclitiom
ORACIER
GELECT
Cotumm-nameo
FRom Tuble náme
1Tuble-mume 9
Join)
1tlis ue ta menge
tao tahtes
Syntuy
Tcuble nume 1. Caumn. melme = Teabhle neupne 2.Coimnmune
E1)EnNAmE DNODamE Loc
SmrTH
s 20
ALEn 30
laer30Lo Da L3
SELECT EnlamEMNAME
EmP EPT
SHERE Enp DNo eDERT. Dno
Joln
2010 CE)
202.3o CE)
Boie20 (F)A
Qesut teble
EnAmE ONAmE
lo20(E)oo SMLTHM
lo 3o(E) ALEA
Employee Detaitg si ond DEPT
Detuis.
Seteet
Penom BmPDEPT
(o9hene Emp. DEPTno=DET,
DEPTDOS
9AQT Empioyee mame Goalcimy locetin
H
they clomg csih
clomg uith
UNeineunmimg aane than 2000
Sélert EaMEGAL oc
SAl 20003
Q9A0TO gmployee mame ß hiG DEetno AbNg
DEPt saame sth
loautiamiP the Smplouee is Cwaikíng
DEpTAO 90
loc DalLAs
SeleetEoAmE, DEPTANAmeG
Seleet
Ponom
ENAmEoc
te whee Emp. D
EPTVO DEPT. DEPT. DO S
9oATD NamE AND SAlagy fan c
he SnPlayee
ACCalantig
SeleetDAmESAL
And
stoai ONAME
ACCOUNTING
AALteshase Silanu aismonethen 9340
Seleet OEeTnAME GALA19
LaOAQTDDANEbnToßfo elmployees
shose emJos DNAME Stunts u9ith
Chnucte.soa
Select DEPTNAmE Toa
n
AAGele at DEPTNAME mceR
Select DEtAMEHIREDATE
Bnomsgme.DERT
9hene mp, ERIAo
=ERI EpTNO AnDE
HIREDATE
>q1-DEC-aTO
DEPTNAmE ACcOUmtingoR
EnnAme R
DrAmE o
the emeloyeesusho
dne yettimg Commm TmDEPT 16 aR 30
eoGeleetErvAmDEPTAAMEo
nom EmpDEPTA
hene Emp OEPTDO DEP. DEPIib AND
COMM TS NOT NULLAND
EMA.OE£TNOIN CIOA0)3
slasIA01DDmermeEapao fos cul the 8mployees ashos
1theme Emp. D
£ptnoe DEPT DEPTN0 A
i2l02l94
ouTER JoLA)
LEEToUTERJotn
LGyntus
GELECt Calummmume
ualana efnom toble ncime1 LEfT buTER To table 2
on doim aConiton
ORALe
SeLEcr
ounm-nuMe
inom table nume 4 tolhle nume 9
Cnolitiom
Emp
ErJAm E Duo
DNAE
20
Da
De
SEIECT
ERom Emp,DEPT
9HERgEnp,Do eDEPT,DnoC+)
Result
tubie
EndAmEo Resosectts
02muachiag
of bot tabre
10 1o
Reooces
ulctchec
LE tabTe
AOniof
9) RICRHT O0TER JoLn)
5392
J4 jG yGe to ohteaim d9matthezlRenel, of he
Riglt teibe nculonaSiHLAMAatehioag Reonds
Synta An4T
C
SELECT Col- nume
fonom teLble mume1 Rigbt outetoun table
ORAcIE
Set Conetiion
Eme
ENAmeDNo0
A
cn 20
D3
FROM emPDEPT
Qesit fubie
A
Do DnAmE
Redhie
bot
lo
30
04of tecked Reten
Acable
D4f_piaki
(3) Fll pTER JOin
AnsTo
GELECT
Columnmane
on
Jon) omclitom
D
Resit tebye
tebje
EnsarME DnAME
Da
Ao0
A
fmetching Reods
D1 of bott tabte
30 Da dnmeLkched Reloxds
4oo:Rigkt folbie
nu 1nmcdched
42nmotChed Aetoxds
13l02|2
42 NATURAL
behutiouNs
behuieccs TmmeToin)Hhene s
bet aseenn neluto
the tublesSNk
bekenes
no nelutoonbeteen he ebreš inGD
ncme
teble mume
Tm nutugnal we olicl
Jon) mot
cnte cmypin
Cn pin
Cosnolitioon
na
Theme ia Conksion in iolemtikying aandon Coumsn
SELE Jon)
Gyntca
GELE CT
blumm- nume
Bsnom
tbleaNe 1
Tor) Tablenume 2
ORACLE
GELECT
CoumM.nune
tablenume i, telble- name9
LEmpE1 EmpE2
ENAME MCAR ENAME meaR
1
eHI)ce
3 2
3 MANNal MANCNÚ
DuNCAL 3
MUN«I4
3-1(P
322()
3-3 T)
EnDAMEMCARAmt
CHLNCA
Tdceln MANCAL
ahene
Qa9AQrD ume
mumaglon Both 2300
EMPloyee
qsmerd
Ql c9AQTD Emp NAME AND MAUACAER S
HIRE DATE TE
EmplouEE 9AS HIRED BEFORE1989
HIREDATE
A5mCAR HIREDATE
30
unmumugen pme
thei glomi es ! gaploy ee Enns
Ecnons mone Haum
theisn
mamageN eR-sAL
SELECT
E1enamE E,eAmE AG mcaR Amb
BEPo.ne Snployee
Eo HTIREDATE1, HIREDATE
ww0RKLnlceTN SAME Jog
NLGELECT1EnAmE EMemE AS m
caR-nemE
Cmp
LmANACAERTG oR3I)ce A
AcrUAL mAnACAER
MANAcAER
AND
S2. SAL Ei. SA.
wAQTD £mployee 'anamE cndmAnAAER'G Desigmutic
on cl| he Smployees
uohene
Gelet BNAmEOEDNDAME
Cnp &2
9lere E2. EMPNo
TooLnmHeletableosCh
m- goiLCoalition
be csniiag
Emp DEPT
81- mce R
e2 EiD
Gne 81
BELEJoin)
o3
GELE
ToL
Jon Bmp S2
JNER
GELE JoL)
24.maR E2.EJD 82,maR s, &1D
Emp &mp 89
DEPT DA DEPT D2
An
2000
An
Momuga
soRmgmneyone ehiauga
Seleot 24
Rmame2EmaNe, RaEMAneD1.Dmune
92DNeD3Dare
tashene
89.DLeID A9DLeINOArM
E3DEpINO D3 DEPI20AND
e1 Se> seest Sa nom gmp shesne
BmineAE
Ds loc
mejmgen mage clogg coi 4hel
4h la he
Epa p Hineod Befo.ne Mejeadleqlmgla
21.DEPTNO D1DEPTNNO
e9.DePnO DeDegTNo
eGDEPTnoD3DEerO
81
HlReDATE<Cselet HsREDATL
hohene EncmegOARTID
83.gel >CGeleto Gc
pseudo Coumná
)Rocb19
e
the eoml
Mest teuble
2oMum qet gemencLte s
ct thetime o
exeoution,
RoêNum eueOeys54et SiHL 1
oSNum is Dyncimie im
Atine
Seleat Rouaum, Rp.
Ronom gonp
Geleet
4Roasum To 4.23
Hous
Benum (lonks
Boleot
emp
aheeRore umaG
1SmiTH
+1
19
+1
JuMAgTIN
443CE)
JAmes
BmiTH
kindce
JAMs
16lo2l24
Janite eA
Quemy to olis Pleag
Selet*
tohene Ratonum
-33
EmP
Rocroum EAnE Se
9 8SoD
3 800
200
S
PRom &onP
1 200
B
3d 300-S
E
6
Gtep
2oiat
VGe he Queny of Step 1
im
Auten Oeny
Step 3:
UGe
the senial ano Gomcliian in -the coheneiCuuse
to get theexpeete utPut
GELEC
Smp.*
RRom &m p)
SLno En)emE
8.00
Prienst
kuf 9eoanoaaf he Sanp feube
seLeet
Bnora
Lohege
Selact
aRARTN tetamo a
hP the Smplayee fuble
SeleetX
1s
Step
eL th D'stiact Sola9iesLm Decem
Landen
G2EC
015TINISA
S000r
90o0-SMcAS
MOUS
80oD
M
9o00
Step 2
3000
200n
6
Gtep g
GELECT SAL
FRom CSELECT
SROm
Rousm AG GLnNO SAL
CSELEC1 DISTIrcT &AL
EROm Emp
ORDER By SaL DESC
SAL
2000
lo2/23
14
Coeto Defimeutiam language )
Sutement taiG use ta Camstnuctamoc'?
Tbia
enel Remaleeim uobjeet Knom he alutobese
stcte emtsof DD
1 eREATE notee TheGe CNe
2>REOAME Cuto Commit
3>
AlTER Gtctements
4 TRUnNeATE
1)
tubre
Thi g Stute ment is use to omstnuct cn obieet
in tha clutibose
Tabie_ume TpRART
Data :
ahek
Checa emgroIauL
NoIONotQlL DotauL
eheak ehec
Caiyso)
bable. mame
F Chstomen
Columns
KEY (lenceTA(n)e
CCin noauGER Cu)PRIMERY CHEEK
llCHECREcA
ReFeneles
1alo2/24
CREATE TABLE
AS
eLGELE CT
FROrm Sonp
To a
Cneute Nieu9
JH c
is
Witeiel ebte ehich is Cneutecl in the hesutt.
Of the Queny
n0t teake cuy kind of stostesge
ail the oletteibse in
cone the anigil eon
toubie it ei
tmpuct n
the Vieu9
hy lemges coae om he iens it ulil impuct
On the oMigimol feuble
CREATE EL9. eu9- ncme
Syatax
AN:CREAIEE9GSALES1
AS
SELECTlk
SmP
HERE Jog2 SALESMAN)
3TRDNCATE
Tis Gtortemesmto jsistol -to2emoleeleleteoL the
9edpèlfnoa theteuhie Panmemtly
Symtux A
laTRUntATÊ TABIATuble mcLme
To ccel eColnlk
Syntux AlTER Ta
BIETcble-emeA
AoD Columm MmeDritetpe Constanciat type
&x
ATER TABIETpKART
PKART
DROP ColDmn ALTERATEo
e
To neName Calumsn
SyntcaaATER TABLE
Tihl lanme
Pg
MoclilyD01 DU
Coastnaintst
Gyntad AlTEg TABLE: Table.mcMe
mapR alJaa) iaai Existiang clutuype
(Oetu magiezulutia
iG
useolco msenthenetomals im he tohle
Tnto fiekunt
FTPKART
Lnten Nulue tom pid 999
Soten 1/uue tos POmecansunckG4
Snten Velue fon pnice gnC00A
100000
Vee Pon
UpoäTel TabieANAME
GET Cal-Aecno 1 Vawe Col-AME 9
lalue
gsCuaheREfntenCosachtioo
js useolta eleletethe pesnHiauloonelode
DELETE
ERomTableAAmE
LiaeREfiten osaclitlom>]s
OELETE
CommT1
Ro)Baci4
CommTT
ThiG
sfotememdS UGe toSave the acansilions.
CammgT
GAVE DOin)T
ig useo to munk Hhe tndnGAcion
Seve
TT ig ugetogeh beiek bedsheuteGt Seleal
Coute Conpna
D Kaguoge
DCARAnNT
RENaRE
CeRAndTA
Thig n
Stetememtis Tusento giveer Pelnmissiom to
T
i4 use to tcie buck ha gilezn Penmiasiam
Ronom he sen
RomUsennume
fROm HR
ComneetLona)
Q1lo2]24
AHnibuteg
1
key etanibute emslialuteiue4
oro ke4 ethnibute
3 Ponime ey thnibute
aon
SComPosite
ponime
e
keyettnibute
ettnibute
Gupen key ethsibute
1foneigan Keeettni baite
4e cttnihute
ymíquely fnon the fhle iGnCalleaf key eittnibute
Bnciamesl epemelenoy
APnial keackionclDepenolemi
3Totagnsisive Bcactfosacd Depemcleasg
Ex wg
det Consioe.nig Relatiocn GHh 4
ettnibite s
A.BC.D Tneohichuditsa yey eittenibute
A
is H.A
A---> B
A---)c
ThejnexisteIE D
Key
DetenaimoR
ettnibute,them thene exiGAGfconsiHiVe
Aimdhiona DepeaelennoA
Ta Hincseagisile Aunchoono: Depemalenoy tioe lae
Key
ct nibatea
Theiim
EistEOdsto
o.mulizutome
tabie iata
BmuleA toble inondlentoRemoe Relunoklmoy
Depeca olem
the te ble to t
nomme fonm
A Reckurn alenc
tuble coithout
Set to Be
in ga1mcu fonm
Aable
P
iG Suid
s
to be in 1stmoNmal faIM
i SoitisPre the folloLoing eonaiioms.
4
table chouuc snoh Lonsista af mat /eahueo alete
9)A teble shoilemot hale DipLeuteian Repeuteol
1/elveg.
2Geeosnd monmal Po.ncCNE)
>A tobte iGcGi to belig s9caHornc) oam
iP iE SathisfreG the Poluncaing Cosnelitio mg.
NoTE
T 4he Cosasiska of ponic)
table
thexn the attaibutes
unctiome
Depenclenoy Resepm.sible
lne Remolel nom the teubte
as Ponm Cane)
Thicl mommcal
1>
A mat
tebie shouldl hele temsiVe PumetHiomol
3.30E