Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Joining to a single record in a child record
Message
From
05/10/2004 16:27:26
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Joining to a single record in a child record
Miscellaneous
Thread ID:
00948927
Message ID:
00948927
Views:
71
Okay I have a customer table with a child table with multiple records.

I need to select data from the parent table and join it the last record from the child table based upon a datetime field.

Something like this but without the error.

select customerid, AH.* from customer
LEFT OUTER JOIN (select top 1 customerid, agentid, inserteddatetime
from activityhistory AH
where AH.customerid = customer.customerid
order by inserteddatetime desc )
on AH.customerid = customer.customerid


The Error is:
Server: Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'on'.

I know it can be done, I've seen it before but I just can't remember where.
Fred Lauckner

You know, it works on my computer. I don't know what your problem is.

.Net aint so bad.
Next
Reply
Map
View

Click here to load this message in the networking platform