Saturday, 15 August 2015

sql - Selecting last occurence of row from table -


I want to select the patient details from the discharge table for 2015-03-16 and select their respective login details from the admission table. .

Discharge table

Enter image details here

Access Table

Enter image details here

. These two tables should be selected using the query that is used in the query with the line red mark

query done:

  Do a.pat_id, a.pat_name, b.admit_date, b.admit_time, b.diagnosis, b.r_name, a.dis_date, discharge_details one from a.dis_time, admission_Details b where dis_date = convert (date, dateADD (day, - 1, GETDATE ()) and a.pat_id = b.patient_id and b.Admit_status = 'Discharged'  

Output Received:

Enter image details here

expected output:

Enter image details here

Please modify your query .. Help me with suggestions

itemprop = "text">

externally are applicable in situations like this:

P>

  select a.pat_id, a.pat_name, b.admit_date, b.admit_time, b.diagnosis, b.r_name, a.dis_date, a.dis_time discharge_details an external apply (selection Top 1 * admission_Details from d where a.pat_id = d.patient_id and d.Admit_status = 'discharged' by admit_date desc order) b Where a.dis_date = CONVERT (date, DATEADD (day, -1, GETDATE)) )  

No comments:

Post a Comment