Hi everyone, hope you are well I need a help for SQL query please. I have a two
ID: 3711146 • 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
Solution:
The query for your requirement is given below:
SELECT PatientId, PatientCode, WorkDate AS LastWork FROM PatientTable INNER JOIN AuditPatient ON PatientTable.PatientId= AuditPatient.PatientId WHERE MAX(WorkDate) GROUP BY PatientId
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.