I have two very simple tables in Oracle 9G:
Customer
userid | firstName | lastName | email
-------+-----------+----------+---------------------
1 user1 User1 user1@mail.in
2 user2 User2 user2@mail.in
Order
orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+-------
1 1 0 12/12/2009 1
2 1 1 13/12/2009 2
3 1 1 14/12/2009 3
4 2 0 12/12/2009 4
5 2 1 16/12/2009 2
6 1 0 14/12/2009 5
7 2 1 17/12/2009 4
8 2 0 10/12/2010 2
I want to select all users which have orders of type 0
select *
from Customer c
inner join Order o on c.userid = o.userid
where o.orderType = '0'
The result is:
orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+--------
1 1 0 12/12/2009 1
4 2 0 12/12/2009 4
6 1 0 14/12/2009 5
8 2 0 10/12/2010 2
Now I need to modify this query to bring only last purchase date for each user id and get the result like this:
orderiD | userId | OrderType | Order_Date | Amount
--------+--------+-----------+------------+--------
6 1 0 14/12/2009 5
8 2 0 10/12/2010 2
How should I modify my query to get this result?
or