SlideShare a Scribd company logo
1 of 7
Download to read offline
Question 2
a)
ERD Diagram
b)
Primary Key
1) Title in movie table is a primary key
2) Director name in director table is a primary key
3) Producer name in production company table is a primary key
4) Actor name in actor table is a primary key.
Foreign Key
There is no foreign key in the tables.
c)
SQL Code
CREATE TABLE Movie (
Id NOT NULL PRIMARY KEY,
Title varchar(255) NOT NULL,
Length varchar(255),
Genre varchar(255),
Quotes varchar (255),
Release Year Date,
);
CREATE TABLE Director (
ID int NOT NULL PRIMARY KEY,
Dir Name varchar(255) NOT NULL,
Dir_DOB varchar(255),
);
CREATE TABLE Actor (
ID int NOT NULL PRIMARY KEY,
Actor_Name varchar(255) NOT NULL,
Actor_DOB varchar(255),
);
Question 3
SQL Statements
a)
SQL Left Join
SQL left join returns all the data from the left table and left join returns only matched data from the right
table.
SQL Right join
SQL right join returns all the data from the right table and returns only matched data from the left table.
Example:
There is a three table in the library database. First table is the Members records, second table is the books
records and the third table is the borrowed records.
Now we apply both left and right join on the above table.
SQL query:
Left join
“ Select members.member_id, borrowed.member_id
from members
Left join borrowed
on
members.member_id = borrowed.member_id
Group By
borrowed.member_id”
“Above SQL statement return all the member id from the member table and returns only matched id from
the borrowed table, This is called left join”.
Right Join
“ Select members.member_id, borrowed.member_id
from members
Right Join borrowed
on
members.member_id = borrowed.member_id
Group By
borrowed.member_id”
“Above SQL statement return all the member id from the borrowed table and returns only matched id from
the member table, this is called right join”.
b)
SQL query
“SELECT count(*) AS ‘noOfBook’
FROM borrowed
WHERE
Member_id =
(SELECT member_id
FROM member WHERE
name = ‘Ali Smith’)”;
c)
SQL Query
“SELECT members.member_id ,
members.name,
borrowed.member_id
FROM members
Inner Join borrowed
ON
Members.member_id = borrowed.member_id
Group By borrowed.member_id
Having borrowed.member_id > 20 ”;
d)
SQL Query
“SELECT book.ISBN, book.authors, book.publisher,
borrowed.ISBN
FROM book
Group By borrowed.ISBN
Having borrowed.ISBN > 10
Where book.publisher = ‘UoL Press’”;

More Related Content

Similar to Solutions1

Similar to Solutions1 (20)

SQL Join's
SQL Join'sSQL Join's
SQL Join's
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Using mySQL in PHP
Using mySQL in PHPUsing mySQL in PHP
Using mySQL in PHP
 
DEF CON 27 -OMER GULL - select code execution from using sq lite
DEF CON 27 -OMER GULL - select code execution from using sq liteDEF CON 27 -OMER GULL - select code execution from using sq lite
DEF CON 27 -OMER GULL - select code execution from using sq lite
 
Sql Server 2000
Sql Server 2000Sql Server 2000
Sql Server 2000
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
SQL Query Interview Questions
SQL Query Interview QuestionsSQL Query Interview Questions
SQL Query Interview Questions
 
Constraints
ConstraintsConstraints
Constraints
 
SQL Database Design & Querying
SQL Database Design & QueryingSQL Database Design & Querying
SQL Database Design & Querying
 
SQL
SQLSQL
SQL
 
Sql
SqlSql
Sql
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq lite
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Les09
Les09Les09
Les09
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
Module 3
Module 3Module 3
Module 3
 
Sql joins
Sql joinsSql joins
Sql joins
 

Recently uploaded

NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...IJECEIAES
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Studentskannan348865
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Studentskannan348865
 
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书c3384a92eb32
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashidFaiyazSheikh
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024EMMANUELLEFRANCEHELI
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Toolssoginsider
 
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...mikehavy0
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Christo Ananth
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxProfASKolap
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentationsj9399037128
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelDrAjayKumarYadav4
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationEmaan Sharma
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 

Recently uploaded (20)

NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 

Solutions1

  • 2. b) Primary Key 1) Title in movie table is a primary key 2) Director name in director table is a primary key 3) Producer name in production company table is a primary key 4) Actor name in actor table is a primary key. Foreign Key There is no foreign key in the tables.
  • 3. c) SQL Code CREATE TABLE Movie ( Id NOT NULL PRIMARY KEY, Title varchar(255) NOT NULL, Length varchar(255), Genre varchar(255), Quotes varchar (255), Release Year Date, ); CREATE TABLE Director ( ID int NOT NULL PRIMARY KEY, Dir Name varchar(255) NOT NULL, Dir_DOB varchar(255), );
  • 4. CREATE TABLE Actor ( ID int NOT NULL PRIMARY KEY, Actor_Name varchar(255) NOT NULL, Actor_DOB varchar(255), );
  • 5. Question 3 SQL Statements a) SQL Left Join SQL left join returns all the data from the left table and left join returns only matched data from the right table. SQL Right join SQL right join returns all the data from the right table and returns only matched data from the left table. Example: There is a three table in the library database. First table is the Members records, second table is the books records and the third table is the borrowed records. Now we apply both left and right join on the above table. SQL query: Left join “ Select members.member_id, borrowed.member_id from members Left join borrowed on members.member_id = borrowed.member_id Group By borrowed.member_id” “Above SQL statement return all the member id from the member table and returns only matched id from the borrowed table, This is called left join”. Right Join “ Select members.member_id, borrowed.member_id from members Right Join borrowed
  • 6. on members.member_id = borrowed.member_id Group By borrowed.member_id” “Above SQL statement return all the member id from the borrowed table and returns only matched id from the member table, this is called right join”. b) SQL query “SELECT count(*) AS ‘noOfBook’ FROM borrowed WHERE Member_id = (SELECT member_id FROM member WHERE name = ‘Ali Smith’)”; c) SQL Query “SELECT members.member_id , members.name, borrowed.member_id FROM members Inner Join borrowed ON Members.member_id = borrowed.member_id Group By borrowed.member_id Having borrowed.member_id > 20 ”;
  • 7. d) SQL Query “SELECT book.ISBN, book.authors, book.publisher, borrowed.ISBN FROM book Group By borrowed.ISBN Having borrowed.ISBN > 10 Where book.publisher = ‘UoL Press’”;