Experiment 4
Experiment 4
___________________________________________________________________________
_ __________________________________________________________________________
Theory:
he Data Manipulation Language (DML) is used to populate the table with values,
T
modify the table values and remove the rows of the table.
he DML statements
T
are: SELECT
I NSERT
UPDATE
DELETE
_ _________________________________________________________________________
Procedure:
n ame text,
price
numeric );
I nserting rows:
The INSERT command requires the table name and column values
I f we don’t have values for all the columns, you can omit some of them. In that case, the
columns will be filled with their default values. For example:
Deleting rows:
Retrieving values:
Example:
1) employee
2) department
d namednodlocation
------------------------------ ----------- -----------------------------------
IT 101 mumbai
COMP 102 mumbai
ETRX 103 delhi
EXTC 104 chennai
account 105 mumbai
4) project
p noplocationpnamedno
----------- ---------------------------------------- -------------------- -----------
1 mumbai website 101
2 chennai coding 101
3 mumbai testing 102
4 delhidocumentaion 103
5) dependents
s sndepname relation
-------------------- ------------------------------ ------------------------------
emp0001nita mother
emp0001sunita sister
emp0002kamal brother
emp0004krishna father
p nossnno_of_hrs
----------- -------------------- -----------
1 emp0001 12
1 emp0002 10
2 emp0001 6
3 emp0004 2
__________________________________________________________________________
ELECT *
S
FROM Restaurant
WHERE Ratings > 4;
ELECT *
S
FROM Reviews
WHERE RestroID = '2';
ELECT *
S
FROM Locations
WHERE City = 'Mumbai';
ELECT *
S
FROM Specials
WHERE FoodType = TRUE;
ELECT *
S
FROM Reservations
WHERE UserID = '16014223049';
ELECT *
S
FROM Reviews
WHERE Ratings = 5.0;
ELECT *
S
FROM Locations
WHERE CState = 'Maharashtra';
ELECT *
S
FROM Reservations
WHERE RestroID = '1';
ELECT *
S
FROM Reviews
WHERE Ratings <4.0;
Output :
f namemnamelnamessn
---------------------------------------- ---------------------------------------- -----------------------------
anitasharmam emp0001
juhiverma r emp0002
krupitajetali v emp0003
nitapatil g emp0004
anitasharma m emp0005
2 )To select names and city of the employees earning salary more then 10000:
Select fname, mname, lname, ecity from the employee where salary>10000;
f namemnamelname ecity
---------------------------------------- ------------------------- ----------------------------------------
anitasharmam mumbai
juhivermar delhi
krupitajetaliv delhi
anitasharma m mumbai
3 ) TO get the details of the cities of the employees in our company:
select distinct ecity from employee;
ecity
------------
delhi
mumbai
4) T o find the name of the department located in Mumbai and with department
number 101:
select dname from department where dlocation=’Mumbai’ and dno=101;
dname
--------------
__________________________________________________________________________________
Questions:
Q2 What is outer JOIN and why is it used? Explain its type with example
Answers :
ns 2.AnouterjoininSQLisatypeofjointhatreturnsalltherecordsfromonetableand
A
thematchingrecordsfromanother,fillinginNULLvalueswherethereisnomatch.Itisused
whenyouwanttoseeallthedatafromonetableregardlessofwhetherithasacorresponding
matchintheothertable,whichisusefulforidentifyingmissingorincompletedata.Thereare
three types of outer joins: LEFT JOIN(orLEFTOUTERJOIN),RIGHTJOIN(orRIGHT
OUTERJOIN),andFULLJOIN(orFULLOUTERJOIN).ALEFTJOINreturnsallrecords
fromthelefttableandthematchedrecordsfromtherighttable;ifthereisnomatch,theresult
is NULL on the right side. For example, if you have a table of customers and a table of
orders, a LEFT JOIN from customers to orders will listallcustomers,includingthosewho
have not placed any orders. A RIGHT JOIN works similarly but returns all records from the
r ighttableandmatchedrecordsfromtheleft,fillingNULLswhenthereisnomatch.Finally,
a FULL JOIN combines the result of both LEFT and RIGHT JOINs, returning all records
when there is a match in either left or right table records, fillingNULLswherethereisno
matchoneitherside.Forexample,usingaFULLJOINoncustomersandorderswillshowall
customers and all orders, including those without a match in the other table. 2.
__________________________________________________________________________________
(A Constituent College of Somaiya Vidyavihar University)
KJSCE/IT/SYBTECH/SEMIII/DMS/2023-24
Grade: AA / AB / BB / BC / CC / CD /DD
__________________________________________________________________________________
References:
Books:
1. E lmasri and Navathe, “Fundamentals of Database Systems”, 6th Edition, Pearson
Education
2. Korth, Slberchatz,Sudarshan, :”Database System Concepts”, 6th Edition, McGraw –
Hill.
WebSite:
1. http://www.tutorialspoint.com/postgresql/
2. http://sage.virtual-labs.ac.in/home/pub/21/