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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql Query help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

5 Posts

Posted - 04/10/2007 :  20:37:25  Show Profile  Reply with Quote
I have a single table "dbo.table_load_tracking" with the following columns:

rowid (pk)
whenloaded datetime
tablename varchar
records int
comments varchar

This query returns max date entry for each table.

Select a.tablename, max(a.whenloaded) From dbo.table_load_tracking a group by a.tablename

Table_Name When_Loaded
table1 2007-03-10
table2 2007-03-10

now I want to add records, comments columns for each record in the above query but still only return the origional list of tablename and max(a.whenloaded)

desired results

Table_Name When_Loaded records comments
table1 2007-03-10 123 xxxx
table2 2007-03-10 222 xxx
just add the two extra columns to the origional data set

Thank You,

Posting Yak Master

216 Posts

Posted - 04/10/2007 :  21:01:16  Show Profile  Visit sshelper's Homepage  Reply with Quote
Try this query:

FROM dbo.table_load_tracking X INNER JOIN
(Select a.tablename, max(a.whenloaded) AS whenloaded From dbo.table_load_tracking a group by a.tablename) Y
ON X.tablename = Y.tablename AND X.whenloaded = Y.whenloaded

SQL Server Helper
Go to Top of Page

Starting Member

5 Posts

Posted - 04/10/2007 :  21:19:26  Show Profile  Reply with Quote
This is exactly what I needed thank you. I would like to practice/learn how to write queries like this do you recommend any particular book or tutorials.

Thank You,
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 04/11/2007 :  09:18:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000