SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Most Recent date query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

icw
Constraint Violating Yak Guru

378 Posts

Posted - 05/02/2013 :  11:56:19  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/02/2013 :  12:07:43  Show Profile  Reply with Quote
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 - 05/02/2013 :  14:59:35  Show Profile  Reply with Quote
thanks lamprey :O)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000