Groups | Blog | Home
all groups > sql server programming > october 2004 >

sql server programming : query problem


Hammy
10/30/2004 10:46:02 PM
Hi all,

I am having a problem creating a query for the following scenario...

I have a table of users (primary key is user_id).
I have a table of orders ( with user_id as a field).

what would the query look like if I wanted to get a list of all users and
their latest order id?

Thanks,
Uri Dimant
10/31/2004 10:23:44 AM
Hammy
SELECT username,max_order FROM users JOIN
(
SELECT MAX(OrderId) max_order,userID FROM Orders group by userid
) as Dev
ON Dev.userid=Orders.userid




[quoted text, click to view]

AddThis Social Bookmark Button