I need to get member personal data for all our members whose subscriptions have lapsed i.e. have a subscription end date before 31/03/2020, however I want to show one member record only (distinct by membership number) ideally the most recent one
I've tried a ROW_NUMBER() solution SQL - Distinct One Col, Select Multiple other? and a cross apply solution sql distinct, getting 2 columns but I can't get it to work.
SELECT membershipnumber AS Id, 
       subscription.enddate 
FROM   [dbo].[userprofile] 
       INNER JOIN dbo.subscription 
               ON userprofile.id = subscription.userprofileid 
       INNER JOIN dbo.subscriptiontype 
               ON subscriptiontype.id = subscription.subscriptiontypeid 
Output is
Id  Enddate
1   2006-04-01 00:00:00.000
1   2001-04-01 00:00:00.000
1   1999-04-01 00:00:00.000
1   1998-04-01 00:00:00.000
1   2008-04-01 00:00:00.000
1   2007-04-01 00:00:00.000
1   2011-04-01 00:00:00.000
1   2005-04-01 00:00:00.000
1   2000-04-01 00:00:00.000
1   1997-04-01 00:00:00.000
2   1999-04-01 00:00:00.000
2   2012-04-01 00:00:00.000
2   2004-04-01 00:00:00.000
2   2001-04-01 00:00:00.000
2   2018-04-01 00:00:00.000
2   2009-04-01 00:00:00.000
2   2005-04-01 00:00:00.000
2   1997-04-01 00:00:00.000
Desired output
Id Enddate
1   2011-04-01 00:00:00.000
2   2018-04-01 00:00:00.000
 
     
     
     
     
    