Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 duplicate problems

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-03-17 : 08:28:27
SELECT distinct A.MEDICATION_NAME,A.MEDICATION_Id,A.ENCOUNTER_ID
FROM EMRMedication A LEFT OUTER JOIN
EMRMEDICATIONSSTATUSLKUP EMS ON A.STATUS = EMS.MEDICATION_STATUS_ID
LEFT OUTER JOIN USERS USR ON USR.USER_LOGIN = A.USER_LOGIN LEFT OUTER JOIN
USERS USSR ON USSR.USER_LOGIN = A.LAST_UPDATED_USER
WHERE MEDICATION_TYPE = 'H' AND PATIENT_ID = '211516' AND STATUS!=0 ORDER
BY MEDICATION_NAME ,MEDICATION_ID,ENCOUNTER_ID

rows are

NADIX ACUTAB DISPERTAB 300mg 2112162 2112180
NADIX ACUTAB DISPERTAB 300mg 2112163 2112181
SPARCIN TAB 200mg 2112161 2112180
SPARCIN TAB 200mg 2112164 2112181
UNICORT VIAL 100mg 2112165 2112181

i want only one one record out of then what is the condition.
onlu either one encounter and patient.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-03-17 : 08:41:25
use row_number function
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-17 : 08:42:18
Remove Distinct
Use min or max for A.MEDICATION_Id and A.ENCOUNTER_ID and group by A.MEDICATION_NAME


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -