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 2012 Forums
 Transact-SQL (2012)
 Most Recent date query

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2013-05-02 : 11:56:19
Hi
I have to write a query that shows 2 columns (Name, Most Recent Activity)

There are two table Table1 has the name and is the primary table
Table2 is a calendar table with many rows for each table1 row. (Although some names will have no rows in table2)
SO I think it is a left join
but I don't know how to do it.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-05-02 : 12:07:43
Something like this?
SELECT 
Table1.Name,
MAX(Table2.Date) AS MostRecentActivity
FROM
Table1
LEFT OUTER JOIN
Table2
ON Table1.Name = Table2.Name
GROUP BY
Table1.name


If that doesn't help, check these links for how to ask your question in a way that makes it eaiser for us to help you:

http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2013-05-02 : 14:59:35
thanks lamprey :O)
Go to Top of Page
   

- Advertisement -