Re: Very Tricky SELECT statement
From: Trey Walpole (treyNOpole_at_SPcomcastAM.net)
Date: 04/05/04
- Next message: Vishal Parkar: "Re: Very Tricky SELECT statement"
- Previous message: Quentin Ran: "Re: WHERE clause question"
- In reply to: Stewart Saathoff: "Very Tricky SELECT statement"
- Next in thread: Stewart Saathoff: "Re: Very Tricky SELECT statement"
- Reply: Stewart Saathoff: "Re: Very Tricky SELECT statement"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 5 Apr 2004 15:09:41 -0500
use a correlated subquery to find the most recent date for the given order,
e.g.
select <orders columns>, <order detail columns>
from orders
join orderdetail on orders.OrderID=orderdetail.OrderID
where orderdetail.orderdate=
(select max(orderdate) from orderdetail where OrderID=orders.OrderID)
"Stewart Saathoff" <stewarts@complete-networking.com> wrote in message
news:eqnpni0GEHA.1264@TK2MSFTNGP10.phx.gbl...
> Hey Everyone,
>
> I have a very tricky select statement that I need help with.
>
> I have a table that contains orders and order details.
>
> I want to retrieve the last detail record from every unique order that was
> placed. The last record is known by the exact date and time that it was
> ordered. The order details table is similar to this:
>
> orderdetid PK int
> orderid FK int
> Item String
> orderdate date/time
>
> I know how to retrieve the last records in a database using the TOP
command.
> but I am not sure how to retrieve every top record from say 5000 orders...
>
>
- Next message: Vishal Parkar: "Re: Very Tricky SELECT statement"
- Previous message: Quentin Ran: "Re: WHERE clause question"
- In reply to: Stewart Saathoff: "Very Tricky SELECT statement"
- Next in thread: Stewart Saathoff: "Re: Very Tricky SELECT statement"
- Reply: Stewart Saathoff: "Re: Very Tricky SELECT statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|