Answers.Body: <p><a href="https://civicrm.org/extensions/summary-fields" rel="nofollow noreferrer">Summary Fields Extension</a> may be your friend. It will create calculated fields for 'latest donation' (and many other such fields) and these are then available in eg Adv Search.</p>
  
  <p>Let us know if that helps with what you are after</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-12T22:54:44.973Z
Answers.LastActivityDate: 2016-12-12T22:54:44.973Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>If I am not wrong you need a SQL Script to list all the contribution in descenting order (Recent transaction) based on a specific membership type ?</p>
  
  <p>If yes, then use this SQL which will give you recent contribution record based on the membership type - so you need to know all the membership type id and replace in the <code>membership_type_id</code> in the SQL below </p>
  
  <blockquote>
    <p>select * from civicrm_contribution a </p>
    
    <p>LEFT JOIN civicrm_membership_payment b ON a.id = b.contribution_id</p>
    
    <p>LEFT JOIN civicrm_membership c ON c.id = b.membership_id</p>
    
    <p>WHERE  a.contribution_status_id = 2 and c.membership_type_id =
    'membership_type_id'</p>
    
    <p>ORDER BY a.id DESC</p>
  </blockquote>
  
  <p>I guess this helps!!!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-01T09:28:47.430Z
Answers.LastActivityDate: 2016-12-01T09:28:47.430Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Body: <p>How do I sort contributions in our database by the most recent contribution date? When I try to search this on the database, it brings up all contributions, not just the most recent and I want to target specific members who have not donated recently. Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-01T03:04:28.280Z
Comments.Text: Can you be a bit more specific. Are you using Advanced Search, or Find Contributions, and if so why doesn't setting the date field filter to just the more recent ones
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-12T22:37:18.793Z
Comments.Text: What I meant by "recent" was that I was getting multiple results for many people and I wanted to only the latest contribution they had made
Comments.UserDisplayName: Erin
Tags: <contributions><sort-order>
Title: Filtering search results to see only the most recent contribution by each contact
ThreadText: # Filtering search results to see only the most recent contribution by each contact
  
  (Asked by: username_0 on 2016-11-30)
  
  How do I sort contributions in our database by the most recent contribution date? When I try to search this on the database, it brings up all contributions, not just the most recent and I want to target specific members who have not donated recently. Thanks!
  
  **Tags:** contributions, sort-order
  
  > **Comments:**
  > **username_1**: Can you be a bit more specific. Are you using Advanced Search, or Find Contributions, and if so why doesn't setting the date field filter to just the more recent ones  
  > **username_0**: What I meant by "recent" was that I was getting multiple results for many people and I wanted to only the latest contribution they had made  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-12-12. Score: 1
  
  [Summary Fields Extension](https://civicrm.org/extensions/summary-fields) may be your friend. It will create calculated fields for 'latest donation' (and many other such fields) and these are then available in eg Adv Search.
  
  Let us know if that helps with what you are after
  
  
  ---
  
  ### Answer by username_2 on 2016-12-01. Score: 0
  
  If I am not wrong you need a SQL Script to list all the contribution in descenting order (Recent transaction) based on a specific membership type ?
  
  If yes, then use this SQL which will give you recent contribution record based on the membership type - so you need to know all the membership type id and replace in the `membership_type_id` in the SQL below
  
  > select \* from civicrm\_contribution a
  >
  > LEFT JOIN civicrm\_membership\_payment b ON a.id = b.contribution\_id
  >
  > LEFT JOIN civicrm\_membership c ON c.id = b.membership\_id
  >
  > WHERE a.contribution\_status\_id = 2 and c.membership\_type\_id =
  > 'membership\_type\_id'
  >
  > ORDER BY a.id DESC
  
  I guess this helps!!!
  
  
  ---
  
  