Click to See Complete Forum and Search --> : how to select latest or last row in a table


alidabiri
10-23-2007, 08:06 AM
HI,
i have two tables: CUST and ORDERS
CUST contains:
cust_num, cust_name, cust_phone

ORDERS contains:
cust_num, order_date, order_amt

i want to list all the customers and their LATEST (LAST) order_amt.
how can i dod this?
thanks.

DARTHTAMPON
10-23-2007, 11:40 AM
what database?

alidabiri
10-23-2007, 03:46 PM
it doesn't matter, really, it's oracle sql.

DARTHTAMPON
10-23-2007, 06:08 PM
actually it does since mssql uses "top", mysql uses "limit" and from what I can see oracle uses "rownum".

try something like this

select *
from (select * from cust order by cust_num desc)
where rownum < 2

and

select *
from (select * from ORDERS order by order_date desc)
where rownum < 2