Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

ASSIGNMENT ~9

NISHTHA GAUR
C0912103

.
QUESTION 1 A
FIRSTLY I CREATED A CUSTOMERS
TABLE NAMED AS CUSTOMERS_103
WITH ATTRIBUTES CUSTOMER_ID THE
DATA TYPE IS INT AND CONSTAINT IS
PRIMARY KEY. IN FIRSTNAME AND
LASTNAME THE DATA TYPE IS
VARCHAR WITH LENGTH 50.
QUESTION 1 A
5 VALUES INSERTED INTO
CUSTOMERS_103 TABLE
QUESTION 1B
IN THIS ORDER TABLE NAMED
AS ORDER_103 WE HAVE
ATTRIBUTES
ORDERED,CUSTOMERID,ORDE
RDATE AND ORDERAMOUNT.
QUESTION 1B
5 VALUES INSERTED INTO ORDERS_103 TABLE
QUESTION 1 C
IN THIS REFUNDS_103 TABLE I
HAVE ATTRIBUTES
REFUNDED,ORDERED,REFUNDD
ATE AND REFUNDAMOUNT
• .
QUESTION 1C
2 VALUES INSERTED INTO
REFUNDS_103TABLE
1.FIND THE DETAILS OF
THE CUSTOMERS AND
THEIR ORDERS (ONLY
THE CUSTOMERS WITH
ORDERS)
EXPLANATION:- THE RESULT SET INCLUDES COLUMNS
FROM BOTH TABLES FOR ROWS WHERE THE
CUSTOMERID VALUES MATCH. THE RESULT WILL BE A
COMBINED TABLE WITH COLUMNS: CUSTOMERID ,
FIRSTNAME , LASTNAME FROM THE CUSTOMERS_103
TABLE, AND CUSTOMERID, ORDERED , ORDERDATE,
ORDERAMOUNT, FROM THE ORDERS_103 TABLE, FOR
ROWS WHERE THE CUSTOMERID VALUES MATCH
BETWEEN THE TWO TABLES.
.
• Why customer 2 appear twice?
• In this case , customer 2 ( with customerid 2) has placed two orders ( order 2 and
order 3 ) , so when you perform the INNER JOIN, you will two rows for customer 2 in
the result set, each corresponding to a different order.
.

• Why customer 5 not appear in the


output?
• In this case , customer 5 exists in the customers_103 table
but does not have any corresponding records in the
orders_103 table. Therefore , when you perform the
INNER JOIN, customer 5 is not included in the result set.
2.FIND THE DETAILS OF
THE CUSTOMERS WITH
ORDERS AND REFUNDS
( JOIN ALL 3 TABLES)
THE RESULT SET WILL INCLUDE
ROWS WHERE THERE ARE
MATCHES IN BOTH THE
CUSTOMERS_103 AND
ORDERS_103 AND REFUNDS_103
TABLES.
.
• Explain the output
• The result set will include columns such as firstname, lastname from the
customers_103 table, orderdate, orderamount from the orders_103 table, and
refunddate, refundamount from the refunds_103 table for rows where both join
conditions are satisfied.
.
• Why only Sara and Rumi apper inthe output
• Sara Davis:
• Sara has one order with OrderID 1, and there is no corresponding refund in the
refunds_103 table for that order. Therefore, Sara's row appears in the result set with NULL
values in the RefundDate and RefundAmount columns.
• Rumi Shah:
• Rumi has two orders with OrderID 2 and 3. Order 2 has a corresponding refund, so
Rumi's row appears in the result set with the RefundDate and RefundAmountcolumns
populated. However, Order 3 has no corresponding refund, so that row is included in the
result set with NULL values in the RefundDate and RefundAmountcolumns
• Other customers like Paul Johnson, Samuel Martinez,Puneet joshi and are excluded
from the result set because they don’t have matching records in both the orders_103
and refunds_103 tables tables based on the specified join conditions.
3.FIND THE DETAILS OF THE CUSTOMERS ORDERS AND REFUNDS IRRESPECTIVE OF WHETHER THEY
PLACE ORDERS OR HAVING REFUNDS
THE RESULT SET WILL INCLUDE COLUMNS SUCH ASFIRSTNAME, LASTNAME FROM THE
CUSTOMERS_251 TABLE,ORDERDATE, ORDERAMOUNT FROM THE ORDERS_251 TABLE,AND
REFUNDDATE, REFUNDAMOUNT FROM THEREFUNDS_251 TABLE. IF THERE ARE NO MATCHING
RECORDSIN THE ORDERS OR REFUNDS TABLES, THE CORRESPONDINGCOLUMNS WILL HAVE NULL
VALUES IN THE OUTPUT.
.

• Explain the output•


• Explanation:
• Sara Davis: Has one order with no refunds.
• Rumi Shah: Has two orders, one with a refund.
• Paul Johnson: Has one order with a refund.
• Samuel Martinez: Has one order with no refunds.
• puneet joshi: No orders, hence all columns from orders_103 and refunds_103
will be filled with NULL values.
• In a LEFT JOIN, all rows from the left table (customers_103 in this case) are
included in the result, and
.

• Why we see NULL values in certain


columns
• NULL values indicate the absence of matching records in the right tablefor
certain rows in the left table. This is a characteristic behavior of theLEFT JOIN
operation. If you want to exclude rows with NULL values,you could consider
using an INNER JOIN instead.
.

THANK YOU

You might also like