0% found this document useful (0 votes)
6 views4 pages

Assignment 3

The document outlines an assignment focused on designing SQL queries using DML statements, including various types of joins, subqueries, and views. It aims to enhance understanding of SQL DML in MySQL and specifies hardware and software requirements for execution. Additionally, it provides theoretical explanations of SQL joins, views, and subqueries with examples.
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)
6 views4 pages

Assignment 3

The document outlines an assignment focused on designing SQL queries using DML statements, including various types of joins, subqueries, and views. It aims to enhance understanding of SQL DML in MySQL and specifies hardware and software requirements for execution. Additionally, it provides theoretical explanations of SQL joins, views, and subqueries with examples.
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/ 4

------------------------------------ASSIGNMENT NO.

3 -----------------------------------------

NAME:

ROLL NO:

Aim: Design at least 10 SQL queries for suitable database application using SQL DML
statements: all types of Join, Sub-Query and View.

Objective:
1. To learn and understand DML statements in MySQL
2. To learn SQL Joins, Subqueries & Views.

Hardware requirements:
Any CPU with Pentium Processor or similar, 256
MBRAM or more, 1 GB Hard Disk or more.
Software requirements:
Ubuntu 14 Operating System, MySQL
Theory:

SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.

Let's look at a selection from the "Orders" table:

OrderID CustomerID OrderDate

10308 2 1996-09-18

10309 37 1996-09-19

10310 77 1996-09-20

Then, look at a selection from the "Customers" table:

CustomerID CustomerName ContactName Country

1 Alfreds Futterkiste Maria Anders Germany


2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico
3 Antonio Moreno Taquería Antonio Moreno Mexico
The "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers"
table. The relationship between the two tables above is the "CustomerID" column. Then, we can
create the following SQL statement (that contains an INNER JOIN), that selects records that have
matching values inboth tables:
Example:
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders INNER JOIN Customers ON
Orders.CustomerID=Customers.CustomerID;

and it will produce something like this:

OrderID CustomerName OrderDate

10308 Ana Trujillo Emparedados y helados 9/18/1996

10365 Antonio Moreno Taquería 11/27/1996

10383 Around the Horn 12/16/1996


10355 Around the Horn 11/15/1996
10278 Berglunds snabbköp 8/12/1996

Different Types of SQL JOINs:


Here are the different types of the JOINs in SQL:
 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the
right table
 RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from
the left table
 FULL (OUTER) JOIN: Return all records when there is a match in either left or right table
 SELF JOIN: (As the name signifies, in SELF JOIN a table is joined to itself.)
SQL Views:
SQL CREATE VIEW Statement
In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains
rows and columns, just like a real table. The fields in a view are fields from one or more real
tables in the database.You can add SQL functions, WHERE, and JOIN statements to a view and
present the data as if the data were coming from one single table.
CREATE VIEW Syntax:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name

WHERE condition;

SQL Updating a View:


You can update a view by using the following syntax:
SQL CREATE OR REPLACE VIEW Syntax
CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...

FROM table_name
WHERE condition;

Now we want to add the "Category" column to the "Product List" view. We will update the view with
the following SQL:

CREATE OR REPLACE VIEW Product List AS


SELECT ProductID, ProductName, Category
FROM Products

WHERE Discontinued = No;

Subqueries:
A subquery is a SQL query nested inside a larger query.
Subquery Syntax :

SELECT column1, column2, ….


FROM table1 outer
WHERE column1 operator
(SELECT column1, column2
FROM table2
WHERE expr1 =
outer.expr2);

 The subquery (inner query) executes once before the main query (outer query) executes.
 The main query (outer query) use the subquery result.

Conclusion:
Thus,we have successfully studied Joins, Subqueries and views and implemented SQL Queries.

You might also like