0% found this document useful (0 votes)
11 views

SQL Notes

1. The document provides SQL commands to create tables and insert data into tables. 2. Examples show how to select data from tables using conditions and operators like WHERE, BETWEEN, OR, and more. Aggregate functions such as SUM, AVG, MIN, and MAX are also demonstrated. 3. The document is a tutorial on basic SQL commands for creating tables, inserting data, and querying data using conditions, operators, and aggregate functions.

Uploaded by

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

SQL Notes

1. The document provides SQL commands to create tables and insert data into tables. 2. Examples show how to select data from tables using conditions and operators like WHERE, BETWEEN, OR, and more. Aggregate functions such as SUM, AVG, MIN, and MAX are also demonstrated. 3. The document is a tutorial on basic SQL commands for creating tables, inserting data, and querying data using conditions, operators, and aggregate functions.

Uploaded by

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

TMD

Data Ba Nanoqumant Sys em (0BMs

h proto a Honaai ng hacallhan data hrdu gh any


30waN onhnapa

Sntax Cvut tabl

cREAT TABLE idariien


Calorunamu C iduiion detadyp CUalus)
Lsi talun
CREATE TABLG EHPloy eE

int C5o)
nam han20),
C29
Dosiainaon y dhani (Ao)

Ihst Camman
ina tuh

Sqwhux-
Insent 'n to toblanama Valwus (daJal , dasa
datun )
ceo'
INSEAT INto Emalaa valvEs I , 'Raut',22 , 'cco
SELECT CONHAND

SELECT olumn nama , Columm ami


Foam taubbs nma

Employ
Nom Quighohon sads

2 A
ROM 5o000
to Kash ctenk

Shulo
D
Aoyank
D
wukku
AnKit
200 Ro- pick
Honsh
ACLaunaut

hanmu 18

Roy Pick
Monish
cleuk
V0-nsh

AnSh 0 So O Monagun

18ha.ah Sweypu
ex slu Nam, DLghath'dn F Tam emple
tmloyu

syndax Al Caduman
SELECT %.

sam t oblenam

. wHERE CIAUSE

+ls used to apup CAndi'han în a qun

Swax-
SELECT calumnama l uumnoms 2

F5m toblanom

WHER Conditan',

Cakumnam

pint Nama o Hha EMplo a who 0


20
oP
SELECT Nama NaMA

FTom Employee ANkit


UHl Ag 2o Ansh
0.wA pi ALL dasails o tmplaya uha noda

SELECT
Fsom Emlayu
wha Gnods=B

+ 18 Vd to Csmpadna a ingla Calwmn wih mulhHh ualua


eca opamatus is nat tapablu to compa sinqk calunn
w Hultipds ualus ut a n tima
.wsiR uuny to pit Nami ay Hu. Emayt
hase a4 is 18,11,20
NAm
SELECT NAME
Emplayt shuuKla
whay Agu In C18 o)
Auh

. wAG t psiw nom a4 n sallany H a


Employa uhe qnads is A,,D
SELECT Nama , AgR Sallany
Fsam emplayn
wha mol n C'a 0)
. NOT (N Ope AToR < )
sELECT ColumnomA l, Ualwmn noma 2 -

FRoN table nam

talwmnamt NoT INC dural, dat 2 dahn)


w hna
- -

.wA to psin all dsuil o tha tm laya whax

wa-d t
SELECT u a A *
Fsam Employe
u hus nade oT iN CB, b?, e')
Log ital opoaha
It is ue with ot lesst hwo Canl'hons
AND opeutoT -

ani+ Getusns t7va 1 both n diti ans a tou

athwwi it wil utuan al

Syntux 2
Calumn om
-

sELECT cotundNAMC ,
F oom hble nam

wh Candih'an 1 AN0 Csnou'h'an 2

. wAG pvid nama alany


emMoa who
SELECT Nan, Sala a l l
Fra Emplayu
hu Aq (t AND
=
Saly200
Noms5alady a
Honh o0
wA to psin* n oma anah'on o a empaya
who Aqu is i h t14 ,2 bust or adaallay is200

sELECT NAME, Designahisn


Foam Employuu
INC 4, 19 ,22) AMD 5allahy 200
wh
olP
Naumt Designation
Hosh Rag pitR
6 OR OPERATo R
hd it retv3n
Ttls used butwean with tuwo Canditn'an

an o hu undit on îs trve auhunuis


T i on

Synax
SELECT ColUMN NMA , tolum nam l-.
Fsom tablnamt
ww tsndih'an los Cod'h'on 2
. WAGto psi alL dails mplo whe AgL is

SELECT *
F30m Employee
whn gu 22 oR hodu ='e

D NomL Ag Salanuy aaudn'on mo


0
6o000 cEO
HoSh
oih
ishnn

NCTNCT cPEah

SELECT Columngm 1, tolumnpmu a - - -

From talble n o
whu NoT Condit'gn) 1wharu alu mn < da
Net eual to

A L to psint Nom, Ag ahay &mployee whose, gnads


not C
sELECT MgHe, A9
yam Employe
NOT

When
S 6ETWECN OPER AToR
JtisV wwn wt hawe to lum pu a singlu ulumn
wh Ronaa

Sywax
SELECT Co lumnoam , tolumn aUmLr
FTOM table hom
wHERE talumnam Betw6eN Valwel ond valwe

wAG t psin* Nom Sallany o


hase emplbs whose 1D s in
baswen 5 25 indudd
SELECT NANE SAN ARR
FT0m EMployee ANO
WHERE 10 8ETWL£N 5 2S

. Distinct CsNMNd
ulwmn
+ &Ud b si dinat dah am a

5yn 0ISTINCT Colomn nam


sELECTT
FRoM uble
oP
A
SELECT DISTIN CT Aso-da
F Tom loyec

NULL
NULL
i0 Agge ok Fun Chan- Vdu tns t h to tl sum o
sdek talum
Sum C)
SELECT Som CColumnnomu)
FSOm table nom
sELECT SuM (Salay
SUm Sal dd
FRoM EM Plbyee

SELECT Sum (8alan)


FRoH Employe oP
Sum (8aday
wh hnad ="e";
.WA pri 3um o Agps o tho Em plogka vhay-
Balla t uMan smallun haun Soo oT 97ada ts C.
sELECT SomCAm)
Fom Emplau
whou Sallan < 5os oR gned =t"
. AUnO - 1t rtus
avonaL valus a 4uleukd
Cawun
Sywuy- SELeCT AUh C ulumnam)
FTaM ablenam
. WA to psint wena4 sallay oumuyu
SELELT Avh ( saloy
Fram Emuyn

0 A h pvid wnaa salang ho emyla


wh qrads is C.
SELECT AUCSalyy) P
F3om Employee io00
who se unads =
*";
2 Hin C)
talumn
T+ etuTnS Hh m'ni mum valuly sulad

Sywhx )
SELECt un Ctolumngumu

F vam hbli noume


Em rloyan
wA O to list M m baly o
SEL&CT nC salony )
Fyom Emalaya 200

WAO. b psind a emldsy wha


a l a is min oP
SELECT Noma, minsalay NuML sala
Houh200
Fyom Emplogtt .Hau'sh 00
SELECT Nam Fvam employ
w 5alaruy= ( 3ELECT Min ( salny ) Fram Employe)

0. wA to psind Noma ond salany Hhos emplaua


who A is g7tade hon th a o Mad'sh

sELECTNAML 5a loy
FTom émplayu
w huu
Aqs>sELEr Ag em tmplay
whu 4> Hanigh
MOx)

Tt3UT ha HaK vallut a ulekd ulwmn


SELECT Nax lu mnama)
Foam tablarama

wA te lis Nax emn emruty tablu

sELECT Hax CAar)


FTam Empluyaa
1CouNT)
Ha to t l

Cowmn sELLCT touNT olumnam)

auhla nom
15. Delk lemman
hom t a h

tax
tablanom
DELETE FRoM

witl d h l ws usm table bu

wi rot du phugi casisu hue


alu ( thuma)

DELETE Fram tablenam

Condi'h' on'
wAL t dail o tho emyluyu
wha eds iy 's
DELETE Fam tmplayn
a whua e =B'
CoMMAND
DRoPDROP Ta6LE
+ib used h dauk hel hihl wih phuar cal

DROP Ta bl Table nome


4updoR emmand

T+is uel to Modiy th dobu o} a table

Syntax
UPDATE ble nam
5ET Lolumn - nw daa

HEAL ndi't'on'

0. RG to irunnasu hu salany all emrlayu by 20

upéa tdg tmployu


SET Salauy Salay t2000

wA to î'nousa H Balany empauu by 20Y.


hoAemalayn wh q l isA,

updak emqlaya
SET Salay (salany*1o) l00
Who qods -'A,
16
6 0RD ER S (oNMAND

os
4 1% used h 0Jdanq dau în Ascending
doscend' n9 ov dn
Fos Ascen d'ng osdu
Asc
DSc Dsndi
0scending
waus in Rscendinqaxdtr
NoR-By dault
dn by

Syntax
SELECT lolumnaML twlomnama
Foam ablenoms
QBeun lasMnam Asc
AsC

wAG t prikt nun ond Agu k e m a y u and onarg


dud uAnding &aluny i'n Ratendi'ng

sELeLT NAME, Ag oP
Foom Employee Houh 4
Mo'sh 1
0dn By saluy Rse 1

. wA t tist l l dthids o tmplayu and

0uang dadu nuanding to a in domndang OT

sELECT k
Fom Emlsy
0D by A Des
t. ALTEK TAABLE CoMMANp

Hd h
T4 ud to adi nw lslumn, dult md h

Cawn
nr t add nw uumn
ALTER TRGLE oub lenomt
ADD nl Caulumn talwmuntyu(sr'y)

wA t add qundun Calwma in hble Emplaya


ALTER Table HRRAYEMploys
ADD aen dun chantto)
Snhunbe diluk ALTER tuba
ALTER TABLE TABLENAME

DROP CoLUMN Columnama,

Column t deht hiAt

9 A t dluk Qundbr Culun ham em playu

ALTER TAbie tmployee


DROP trteR (alumn hendon
to ths s dulumn
synta Mod
ALTER TABLE TABLENAME

Ho diy
Mo di olumnama tolomatya
(nw siu )
nm
. wA b Mo dil osthangi s y a
Calamn upto So am table empla
ALTER TABLE EMpLoY¬
Hodity Nam Unchun (g6)
o ike laus
.Fosun dli nd angth ossbs+aing
(undens(ove)se) Fos duuin kngh substang
hu ungnstw = lhon auten

SELECT ColumnamL| olumnam .

F RoM tablenam

whan olomnamt ukdada .


OR

)Painall dahul Hho emlayu u hasLnom.


shuing a m R

SELECTx F3om EmpLOYE E


thosn emalayu hose Name is
) Psind al dtaily
Stonhing am k a n n o m is a thanaut
SELECT F ToM ENPLOYEE
wHEAE NANE tr'ta R - - '

. wAG. to than tha balany e m rdayn vp t


oL lokh wha nameb Fants wi h ond
Setand la h nami ss.

pdoe Employea
5e balay = lo o o00

w nama tik HYS-

. AO to daduk. Hha dhils t h o u emplayu


whese serond th is a and Hisd lat Ch Js iol

nom

DELETE FRoM Employ ee


ww noma iiksa7. - -
21. ARoup Y-I*S Used fus gTouping Ha data 1f,
Should hawe otleast d
4tqak funh'ah an
apdai ng Cn d h'ors wh'e huwptng hadasa
C uib USing dop by we Can't ust w h
Uaw o insttod w h w clws
whwt u u
5elect ColmnaM a44uawH unuion
F Tom table hani

whe up 4 Columnom,

ca7 SELECT Asod HaxC salary )


F Bom Employe
fvnas p By madt
. A a t fnd MagiMuUN alany , muN MUm Aalany
ond Coun to tal
n emla tn eauh grada

ads Nax (salay ) mn (Saleoy)


sELECT

Cawnt * ) hamemployee
wrawp b hheds
u n (sala) wntt*)
w Hax (salay
A S oo
So0o o o0

S0 0

2o0
So0
Houing l awse
nlardui'ng H
Tis Ud apry landi h'ons
dada.
Synhux
sELECT Cslumnam , 00.tunhh
F7om toblenom

hToup b Columnama
Haw'n Can dd h'on'

A&H print om salang aRth qnods whu


tta mdAyai ik gnatn han

SELECT hros Som Salay


FTam Emrla
wp b hod
Hayi'ng Count *7
ofp
hra d Sum salay
ToINs
Joins

what obje tt w'h obect

Employ
Id NomsAE|Saly 1 0esignah'as DCod
t Rgwi 22
to Kwh 2000 Mangi
3 Nonu'sh 23 CA
vOnsh 1Soo cleuk
Ankit 22 innoal AlC
shwkla 23 supewrsos
1shaan Soo0 Assi tand

Depandm
D deonomu
lo ACuwn A
o2 SALE
o3 NARKETI N

SERUICES
D

Syntox Col umnML


ClUmnumg
5eLeCT
Fsam tble l , tab
w ht uublut.coMMan talumname h h l e , Connan
Calurnan
x . SELeCT Namt Salay, D Ngmn
FRoM &mploy, Dapatmut

hn
Emlaya dcods Depadmunt, Dtods

NoumL
saa Onam
Mankattng
ROA
oKash SA LE

seL£CT Nom Salpu DNom

FRoN Employee Depaxdmun


Depaadmant.Do o n
when mploy O to da =

NomL D Numa
HouAh ACuaUnt

Ankit ACCoUndat
uith objet
seLECT Columnam I, Caulumnam
7um tbbl I obiLt1, tuhl ? a b t
Lamain tulu mmaml
wht ob ulCalu mnum =ob l t . Caman
AND Cand h'on

SELECT Nom Salay Onoms

Foom Emplayl A Deponnent p


,

whOL A Dcoda = B. Dcads AND B-nos -'a°


06

You might also like