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
 General SQL Server Forums
 New to SQL Server Programming
 Sql Query help

Author  Topic 

fullyii
Starting Member

5 Posts

Posted - 2007-04-10 : 20:37:25
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,
fullyii

sshelper
Posting Yak Master

216 Posts

Posted - 2007-04-10 : 21:01:16
Try this query:

SELECT X.*
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
http://www.sql-server-helper.com
Go to Top of Page

fullyii
Starting Member

5 Posts

Posted - 2007-04-10 : 21:19:26
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,
Fullyii
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-11 : 09:18:04

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -