LAB 08 Retrieving Data From Multiple Tables: Theory
LAB 08 Retrieving Data From Multiple Tables: Theory
THEORY
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.
Syntax
Example
Syntax
Example
Syntax
Example:
SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL
OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID ORDER BY
Customers.CustomerName;
TASKS:
(I) Consider the following relation
3. Write a SQL statement to make a list in ascending order for the salesmen who
works either for one or more customer or not yet join under any of the
customer.
ANS: select * from customer where eid=(select eid from saleman order by
eid asc);
4. 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