Professional Documents
Culture Documents
LAB # 04
Data Retrieval Operations using Join operations
The JOIN Statement:
One of the most powerful features of SQL is its capability to gather and
manipulate data from across several tables. Without this feature you would
have to store all the data elements necessary for each application in one table.
Without common tables you would need to store the same data in several
tables. Imagine having to redesign, rebuild, and repopulate your tables and
databases every time your user needed a query with a new piece of
information. The JOIN statement of SQL enables you to design smaller, more
specific tables that are easier to maintain than larger tables.
SQL JOIN (INNER JOIN) An SQL JOIN clause is used to combine rows
from two or more tables, based on a common field between them. The most
common type of join is:
SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows
from multiple tables where the join condition is met.
Examples:
SQL LEFT JOIN Keyword :The LEFT JOIN keyword returns all rows
from the left table (table1), with the matching rows in the right table (table2).
The result is NULL on the right side when there is no match.
SQL RIGHT JOIN Keyword The RIGHT JOIN keyword returns all rows
from the right table (table2), with the matching rows in the left table (table1).
The result is NULL in the left side when there is no match.
SQL FULL OUTER JOIN Keyword The FULL OUTER JOIN keyword
returns all rows from the left table (table1) and from the right table
(table2). The FULL OUTER JOIN keyword combines the result of both
LEFT and RIGHT joins.
TASKS:
CUSTOMER_ID, SALESMAN_ID).
● Write a SQL statement to know which salesman are
working for which customer.
● Write a SQL statement to make a list in ascending order for the
customer who works either through a salesman or by own.
● Write a SQL statement to make a list in ascending order for the
salesmen who works either for one or more customers or not yet
joined under any of the customers.
● Write a SQL statement to make a report with customer name, city,
order no. order date, purchase amount for those customers from the
existing list who placed one or more orders or which order(s) have
been placed by the customer who are not in the list.