Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 selecting only recent visits for person

Author  Topic 

ujjaval
Posting Yak Master

108 Posts

Posted - 2007-12-03 : 23:24:29
Hi all,

I have a problem for query.

I have a table containing PersonID, Date_of_Visit.

This table has basically data for each person's all the visits with the date they visited.

Now, I need to know only the recent date for each person in the table through query.

How can I get that.. So, output will be something like this:

PersonID RecentVisit
1 29-Sep-2007
2 30-OCT-2007
3 10-July-2007
... and so on.

Thanks,
Ujjaval

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2007-12-03 : 23:47:08
select personid, max(date_of_visit) as recentVisit from <yourTable> group by personid

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -