开发者

Getting the last record of a user in a table

A stored procedure I am working on from a previous developer is joining many tables together to return one record of a "participant" for a particular event. One table in question may not have the information for that event, however I still need to return certain data of that participants LAST entry into that stored procedure. There is a datalastmodified column, but that is not one of the fields being return. How do I return the data in question within the stored procedure of the last e开发者_如何学Gontry?

Here is a sample; if a user enters a participant that is not affiliated with the current event it needs to look in the EventAffiliation table for the last entry of that participant:

table ParticipantGenInfo

userid,
eventid,
firstname,
lastname,

table EventAffiliation

userid,
eventid,
field,
degree,
degreeyear,
datelastmodified

stored procedure example (left join is actual code)

select
     pgi.userid,
     pgi.firstname,
     pgi.lastname,
     ea.field,
     ea.degree,
     ea.degreeyear
from ParticipantGenInfo pgi
left join EventAffiliation ea
     on pgi.userid = ea.userid and pgi.eventid = ea.eventid
where pgi.eventid = 'xxxxx'


Your question is too vague to answer, but you will want to have a query something like this:

SELECT TOP 1 ... FROM ... LEFT JOIN ... ORDER BY DataLastModified DESC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜