DBMS GradedLab4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Laboratory Assignment Sheet

Instructions:

 Download this document and solve them during the laboratory time.
 Insert SAPID and NAME at the top of the sheet before submission

Name – Chinmay Pathak SAPID - 1000013906

Q: Create two tables-


First table (salesman) contains SaleID, SaleName, City and commission.
Second table (customerOrder) contains CustID, CustName, City, OrderAmount.
OrderDate and SaleID

 Write a query to join these two tables.


 Write a query to join these two tables so that all rows from salesman are in
the result
 Write a query to join first table to itself.
 Write a query to join more than three tables. (First create two more tables)
 Write query to differentiate between a left and full join.
Note: Attempt all queries
Laboratory Assignment Sheet

Answer:
Create Tables
Salesman table:

CREATE TABLE salesman (


SaleID INT PRIMARY KEY,
SaleName VARCHAR(50),
City VARCHAR(50),
Commission DECIMAL(10, 2)
);

CustomerOrder table:

CREATE TABLE customerOrder (


CustID INT PRIMARY KEY,
CustName VARCHAR(50),
City VARCHAR(50),
OrderAmount DECIMAL(10, 2),
OrderDate DATE,
SaleID INT,
FOREIGN KEY (SaleID) REFERENCES salesman (SaleID)
);

Queries:
 Write a query to join these two tables.

 Write a query to join these two tables so that all rows from salesman are in
the result
Laboratory Assignment Sheet

 Write a query to join first table to itself.


 Write a query to join more than three tables. (First create two more tables)

Creating 2 more tables:

SELECT so.CustID, so.CustName, s.SaleName, p.ProductName, od.Quantity, p.UnitPrice


FROM salesman s
JOIN customerOrder so ON s.SaleID = so.SaleID
JOIN orderDetails od ON so.OrderID = od.OrderID
Laboratory Assignment Sheet

JOIN product p ON od.ProductID = p.ProductID;

 Write query to differentiate between a left and full join.

You might also like