SELECTING LAST TWO ENTRIES
HOW CAN I SELECT THE LAST TWO ORDERID'S FOR EACH CUSTOMERID
ORDERID
CUSTOMERID
ITEM
QUANTITY
# 1 Re: SELECTING LAST TWO ENTRIES
"sheryl kemp" <dianedinero@aol.com> wrote:
>
>HOW CAN I SELECT THE LAST TWO ORDERID'S FOR EACH CUSTOMERID
>
>ORDERID
>CUSTOMERID
>ITEM
>QUANTITY
>
Hi!
Asuming:
1) that the two last orderID's is also the two greatest orderID's on each
customerID.
2) a sett of customerid and orderid only appear once
then try this..
select * from YOUR_TABLE YT1
where YT1.orderID in
(
select top 2 YT2.orderID
from YOUR_TABLE YT2
where YT2.customerid like YT1.customerid
order by YT2.orderid desc
)
-Kudel:)
Kudel at 2007-11-11 23:52:28 >

# 2 Re: SELECTING LAST TWO ENTRIES
Yes, this is definitely the concept and thank you for your response. Would
the following scenario also use the query you outlined below
SELECTING THE LAST TWO PENDING_NOTES ENTRIES IN THE TABLE FOR EACH PENDING_ID
(HERE, i BELIEVE IF I CAN GET THE TWO LATEST PENDING_DATE_TIMESTMP'S, IT
WILL GIVE THE DESIRED OUTPUT)
PENDING_ID
PENDING_TYPE_ID
PENDING_DATE_TIMESTMP
PENDING_NOTES
>
>Hi!
>
>Asuming:
>1) that the two last orderID's is also the two greatest orderID's on each
>customerID.
>2) a sett of customerid and orderid only appear once
>
>then try this..
>
>select * from YOUR_TABLE YT1
>where YT1.orderID in
> (
> select top 2 YT2.orderID
> from YOUR_TABLE YT2
> where YT2.customerid like YT1.customerid
> order by YT2.orderid desc
> )
>
>-Kudel:)