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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 A Great Query

Author  Topic 

shane1890
Starting Member

3 Posts

Posted - 2010-01-15 : 10:19:08
One table. One query. Could you please help?

I have a table called PROJECT. Projects can be baselined whereupon a copy is made in the table but this time with the original project name appended with a baseline number. I'll give you an example:

PROJECT
proj_id orig_proj_id proj_name

1 null Project One
2 null Project Two
3 1 Project One - B1
4 1 Project One - B2
5 2 Project Two - B1
6 1 Project One - B3


I would like a query that returns the most recent baseline of each project, such as follows:

RESULT
proj_id orig_proj_id proj_name

5 2 Project Two - B1
6 1 Project One - B3


Notes:
* proj_id is primary key
* No two projects will have the same name
* The baseline numbering is consistent (B1, B2, B3, ... )
* You CANNOT assume anything about the numbering of proj_id, just that it is a primary key

I was thinking of using something like
SELECT TOP 1 * FROM PROJECT WHERE ??? ORDER BY PROJECT.proj_name DESC
but I am not sure.

Any help greatly appreciated!

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-15 : 10:20:39
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=138417

Please do not cross post.
Go to Top of Page

shane1890
Starting Member

3 Posts

Posted - 2010-01-15 : 10:30:23
I wanted to delete the other one since this forum seems more relavant but I don't know how to delete threads. Sorry. Anyway, thanks for the answer, I'll try it out.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-15 : 10:45:22
"I wanted to delete the other one "

The button on the post (which only you, as author, will see). But once someone has answered its too late ...

There is an Edit button too - so you can re-edit your post, if you need to.

We like to have no cross posting here, otherwise people start answering in both threads and it all gets very confusing

The MODs will move your post if you ask them nicely, but everything is about SQL here, so probably not that important ...
Go to Top of Page
   

- Advertisement -