By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,450 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,450 IT Pros & Developers. It's quick & easy.

SQL question ( retrieving records based on a priority order )

P: n/a
Hi all,

I have a table with this structure:

Customer ID | Transaction date | Transaction type
1 | 1/2/2008 | F
1 | 1/4/2007 | M
1 | 1/2/2008 | R
2 | 1//5/2007 | M
2 | 1/6/2007 | R
For each customer ID, I need to retrive only the records with the most
recent transaction date, and I did:

Customer ID | Transaction date | Transaction type
1 | 1/2/2008 | F
1 | 1/2/2008 | R
2 | 1/6/2007 | R

The problem is, each customer can make more than one transaction in
the same day (see above). In these cases, I need to retrieve only one
record per customer, based on the importance of the transaction: F is
more "important" than R which is more "important" than M. So, in the
example above, I would only retrieve transaction F for customer 1 and
disregard transaction R: they were made on the same date, but I am
more interested in F than in R.

Do you have any suggestions on how I could achieve this in SQL?

I use Microsoft SQL server 2005.

Thank you for your help!
Feb 22 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thank you all for your precious tips!
Feb 24 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.