I have a table that contains data about the patient. The table has
Admission date, among other things. The same patient can have multiple
Admission date. I am interested only in selected patients whose entry date is on a selected date. For example: the table below
patient_id | admission date F001 2018-07-13 F002 2017-04-02 F003 2018-07-13 F004 2018-04-05 F005 2015-06-13 F001 2017-04-02 F002 2018-07-13 F001 2018-04-22
In the table above,
F001 It has 3 admissions:
2018-07-13, 2017-04-02, 2018-04-22 Y
F002 it has 2:
Now, I have a spreadsheet of the IDs with their dates of admission in the next column. I took the identifiers and dates separately, and added them to the following query
WITH THE TABLE TO COMO SELECT CONVERT (date, admission_date) as admit date, * From the entrance table WHERE the patient ID in (& # 39; F001 & # 39 ;, & # 39; F002 & # 39 ;, & # 39; F003 & # 39 ;, & # 39; F004 & # 39 ;, & # 39; F005 & # 39 ;)) SELECT * FROM TableA WHERE adm_date IN (& # 39; 2018-07-13 & # 39 ;, & # 39; 2017-04-02 & # 39 ;, & # 39; 2018-07-13 & # 39 ;, & # 39; 2018-04 -05, & # 39; 2015-06-13 & # 39;, & # 39; 2017-04-02 & # 39;, & # 39; 2018-07-13 & # 39 ;, & # 39; 2018- 04-22 & # 39;)
This gives me the result I'm looking for but also more than what I'm looking for. It gives me even the rows of the patient whose entry date is also on the list of dates I'm looking for, not the ones listed on the spreadsheet. Basically, the query provides me with multiple data for the same patients instead of just the row with the date I need.
How can i fix this? What is the best way to handle it?
The desired result should be something like the following:
patient_id | admission date F001 2018-04-22 F002 2018-07-13 F003 2018-07-13 F004 2018-04-05 F005 2015-06-13