Hi,
I have 2 tables record patient id, inpatient and outpatient date.
Out_Patient table:
p_id, out_date
001, 2001/1/1
001, 2002/2/15
001, 2002/3/7
002, 2002/6/6
002, 2004/5/20
003, 2003/7/8
In_Patient table:
p_id, In_date, Last_Out_date
001, 2000/12/21
001, 2002/2/10
001, 2002/3/5
002, 2002/6/1
002, 2004/5/18
003, 2003/7/7
When a patient comes in, I need to retrieve his previous out_date and update it in the Last_Out_date Column. So the result of In_Patient table suppose to be:
p_id, In_date, Last_Out_date
001, 2000/12/21
001, 2002/2/10, 2001/1/1
001, 2002/3/5, 2002/2/15
002, 2002/6/1
002, 2004/5/18, 2002/6/6
003, 2003/7/7
I've used min() function but didn't work the way I wanted. I'd appreciate if anyone could tell me how to do this.