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 2000 Forums
 SQL Server Development (2000)
 Returning a set comprised of the last dated record for a selection of subsets?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-06 : 09:57:49
Evan writes "Boy this has been really stumping me.

I have a table called STATUS. It essentially is a log of status updates for customers, and any other database entry from any other tables. So what happens is that a customer for instance may have 5 or 6 STATUS records about the status of their membership. maybe at one point they breached our customer agreement and we created a Date Stamped STATUS record of that. Then later they corrected their breach with our company and we inputted a new STATUS record reactivating their account. We prefer this because we can then view the complete history of the progress of anything our STATUS records are linked to. A customer could view their whole STATUS history to see when they became a customer etc.

Well, I have two questions.

1) How do we make a query that will return everyone's (from the related table CUSTOMERS) last status according to the dates stamped on each status record in the table STATUS?

2) How could we return everyone (From the related table CUSTOMERS) who's last STATUS entry is, for instance, "Breach"?

I have a notion that this will use the IN operator and a few GROUP BYs and ORDER BYs but I just cannot seem to be able to conceptualize it.

Can you, the SQLguru, help?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-12-06 : 10:52:37
Try this:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=10476

Just modify it to match your column and table names.

Go to Top of Page
   

- Advertisement -