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
 General SQL Server Forums
 New to SQL Server Programming
 Sql Query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

fullyii
Starting Member

USA
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,
fullyii

sshelper
Posting Yak Master

216 Posts

Posted - 04/10/2007 :  21:01:16  Show Profile  Visit sshelper's Homepage  Reply with Quote
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

USA
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,
Fullyii
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

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

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
  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