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.
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 varcharrecords 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.tablenameTable_Name When_Loaded table1 2007-03-10table2 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 resultsTable_Name When_Loaded records commentstable1 2007-03-10 123 xxxxtable2 2007-03-10 222 xxx .... just add the two extra columns to the origional data setThank 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) YON X.tablename = Y.tablename AND X.whenloaded = Y.whenloadedSQL Server Helperhttp://www.sql-server-helper.com |
|
|
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 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|