Hi everyone, hope you are well I need a help for SQL query please. I have a two
ID: 3711056 • Letter: H
Question
Hi everyone, hope you are well
I need a help for SQL query please.
I have a two table which first called PatientTable and second Called AuditPatient table
I have a PatientId and PatientCode in both tables.
And also in First table I have Column which is WorkDate.
Something like this;
PatientTable:
PatientId PatientCode
123456 ABC
987654 BCD
AuditPatient:
PatientId PatientCode WorkDate
123456 ABC 01/01/2001
123456 ABC 01/01/2001
123456 ABC 01/02/2001
123456 ABC 10/20/2005
987654 BCD 12/23/2005
987654 BCD 12/23/2005
987654 BCD 01/10/2017
Then I want the join SQL query to show the LastWork and check if WorkeDate Column have same date time only shows one not all the record that have same time LastWork.
I need the query result be like this
PatientId PatientCode LastWork
123456 ABC 01/01/2001
123456 ABC 01/02/2001
123456 ABC 10/20/2005
987654 BCD 12/23/2005
987654 BCD 01/102017
Does anybody can help me for this please?
Best Regards
Explanation / Answer
select distinct (a.PatientId, a.PatientCode, a.WorkDate AS 'LastWork')
From AuditPatient AS a, PatientTable AS p
Where a.PatientId = p.PatientId;
Join on PatientID.
Here, we are selecting distinct rows. Distinct keyword will not repeat any rows.
Your purpose is solved.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.