Hello everyone:
I am doing a sql exercise which states like this, "Determine which orders have not yet shipped and the name of the customer that placed each order. Sort the results by the date on which the order was placed."
this exercise asks me to use traditional approach(using where clause along with outer join operator(+), and using the join keyword)
the tables used for this exercise is customers and orders. the data type of each table are as follows:
customers table: contaion all the customers who placed orders and who have not recently placed an order
Name Null? Type
----------------------------------------- -------- --------------------
CUSTOMER# NOT NULL NUMBER(4)
LASTNAME VARCHAR2(10)
FIRSTNAME VARCHAR2(10)
ADDRESS VARCHAR2(20)
CITY VARCHAR2(12)
STATE VARCHAR2(2)
ZIP VARCHAR2(5)
REFERRED NUMBER(4)
order table: this table contains data for current month orders or unfilled orders from previous month.
Name Null? Type
----------------------------------------- -------- ---------------
ORDER# NOT NULL NUMBER(4)
CUSTOMER# NUMBER(4)
ORDERDATE DATE
SHIPDATE DATE
SHIPSTREET VARCHAR2(18)
SHIPCITY VARCHAR2(15)
SHIPSTATE VARCHAR2(2)
SHIPZIP VARCHAR2(5)
the two tables have customer# attribute in common. I think I should use outer join for this exercise. I did several tries. i guess i am still little confused about the defination for ourter join when it comes to using 'join' keyword along with left, right full option.
I did three attempts but each one give me different results. I couldn't figure out which one is right. Please help.
--My own selection statement are as follows:
a) traditional approache (using where clause)
select order#, lastname, firstname, shipdate
from customers c, orders o
where c.customer# = o.customer#(+)
order by o.shipdate
27 rows were selected
my thinking on this is if there is no corresponding row in customers table, which means that customer who have not been place an order recently. the results will display customer who have not been place an order recently. what if I put (+) on left side will this give me the correct result?
b) use join keyword.
select lastname, firstname, order#, shipdate
from customers c right join orders o
on c.customer# = o.customer#
order by o.shipdate
21 rows were selected.
Please give me some suggestion on how to solve this problem. if you know some good web source that give clear explnation on outer join along with examples, pleate refer them to me. I will appreciate your help!
Sincerely,
sjgrad03
1-25-05