Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Petehe
Starting Member
20 Posts |
Posted - 2003-10-24 : 03:23:04
|
| Table ACustomerIDCustomerNameTable BOrderIDOrderDateCustomerIDOrderPriceI would like to have a list with all customers and their last order price.My Sql is Select CustomerName, orderPrice from A right outer join B on A.CustomerID=B.CustomerID and orderDate=(select max(orderDate) from B)But "orderDate=(select max(orderDate) from B)" have some problem, it try to get the max order date for all customers not base on on the max order of each customer.can any one help me with that?Thanks. |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-10-24 : 03:57:48
|
| select CustomerName,(select top 1 OrderPrice from B where B.CustomerID=A.CustomerIDorder by OrderDate desc) LatestOrderPricefrom A |
 |
|
|
Petehe
Starting Member
20 Posts |
Posted - 2003-10-24 : 04:13:36
|
| Thank you so much |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-10-24 : 04:25:46
|
| You are welcome!! :) |
 |
|
|
|
|
|