T-SQL get one records from multiple same record based on max value for join


Let's say you have same type 6 record, into this record when you will picked data you will pick only one record which has highest value.




 SELECT *   
 FROM rx r  
 INNER join   
  (SELECT distinct t1.*  
 FROM profile t1  
  LEFT OUTER JOIN profile t2  
   ON (t1.rxno_FK = t2.rxno_FK AND t1.nrefillno < t2.nrefillno )  
 WHERE t2.dispid_PK IS NULL) AS p ON r.[rxno_PK] = p.rxno_FK  






Popular posts from this blog

mvc razor textboxfor change event change another textboxfor value

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report