troubleshooting Question

Query Help-Top Row for multiple selection

Avatar of Star79
Star79Flag for United States of America asked on
Microsoft SQL Server 2008
8 Comments1 Solution277 ViewsLast Modified:
Hello All,
I have the below query,is there a way to return the top 1 row for each facility ie '261','262','40'.
Thank you.

 select   FacName,rxs.FacID,rxs.PatID, rxs.rxno,rxs.PhNPI,PhName,NsID,Room,patients.PatFName,patients.PatLName,rxs.DrugLabelName,sig,
 CardIDNo 
 , InsName
 ,errors.SeqNo
 ,errors.RejectCd
 ,errors.Submitted
,"ECSRejectCds"."Description"
,ECSRejectCds.ECSRejectCd
 --
 from Rxs
 left join Facilities on rxs.FacID = Facilities.FacID
 left join Patients on rxs.PatID = patients.PatID
left join vw_crystal_ReorderDirectionsExpandedSig vw on rxs.FacID = vw.FacID and rxs.RoNo = vw.RoNo and rxs.PatID = vw.PatID
left  join PatientMOPs on rxs.PatID = PatientMOPs .PatID and rxs.FacID = PatientMOPs.FacID and rxs.MOP = PatientMOPs.InsID 
left join InsPlans on rxs.MOP = insplans.InsID
left join ECSHistoryErrors errors on rxs.FacID = errors.FacID and rxs.PatID = errors.PatID and rxs.RxNo = errors.RxNo
left JOIN "FwReports"."dbo"."ECSRejectCds" "ECSRejectCds" ON errors."RejectCd"="ECSRejectCds"."ECSRejectCd"
 where  "Rxs"."RxBatch"='TP-RPH'
 and   CardIDNo is not null 
 and ECSRejectCds.Ver='D.0'
 and rxs.FacID in('261','262','40') 
  order by Submitted desc ,SeqNo desc
ASKER CERTIFIED SOLUTION
Star79

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros