Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sixdeep357
Starting Member
2 Posts |
Posted - 2008-05-08 : 12:02:11
|
| Hi. I've only been working with sql for a few weeks now and I'm trying to join multiple tables. I've pasted my query below. It works except for the fact that I get two records (exact same data in each field) for each patient when I run it. I must not have a clear understanding of how the join works. Does anyone happen to know why I get two of each patient record and how I might change the query to return only one entry per patient?ThanksSELECT dbo.caseintraop.anes_start_datetime, dbo.caseintraop.anes_stop_datetime, dbo.casemain.casemain_id, dbo.caseintraop.pat_or_in_datetime, dbo.caseintraop.pat_or_out_datetime, dbo.casereslist.res_id, dbo.casereslist.room_in_datetime, dbo.casereslist.room_out_datetime, dbo.casereslist.resrole_id, dbo.casemain.pat_displayname, dbo.casemain.pat_mrn, dbo.casemain.pat_acct_num, dbo.anestypelist.anestype_id, dbo.resrole.name, dbo.casereslist.res_nameFROM dbo.casereslist INNER JOIN dbo.casemain ON dbo.casereslist.casemain_id = dbo.casemain.casemain_id INNER JOIN dbo.caseintraop ON dbo.casemain.casemain_id = dbo.caseintraop.casemain_id INNER JOIN dbo.anestypelist ON dbo.casemain.casemain_id = dbo.anestypelist.casemain_id INNER JOIN dbo.resrole ON dbo.casereslist.resrole_id = dbo.resrole.resrole_idWHERE (dbo.resrole.name = 'ANESTHESIOLOGIST') OR (dbo.resrole.name = 'CERTIFIED REGISTERED NURSE ANESTHETIST') |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-08 : 12:19:39
|
quote: Originally posted by sixdeep357 Hi. I've only been working with sql for a few weeks now and I'm trying to join multiple tables. I've pasted my query below. It works except for the fact that I get two records (exact same data in each field) for each patient when I run it. I must not have a clear understanding of how the join works. Does anyone happen to know why I get two of each patient record and how I might change the query to return only one entry per patient?ThanksSELECT dbo.caseintraop.anes_start_datetime, dbo.caseintraop.anes_stop_datetime, dbo.casemain.casemain_id, dbo.caseintraop.pat_or_in_datetime, dbo.caseintraop.pat_or_out_datetime, dbo.casereslist.res_id, dbo.casereslist.room_in_datetime, dbo.casereslist.room_out_datetime, dbo.casereslist.resrole_id, dbo.casemain.pat_displayname, dbo.casemain.pat_mrn, dbo.casemain.pat_acct_num, dbo.anestypelist.anestype_id, dbo.resrole.name, dbo.casereslist.res_nameFROM dbo.casereslist INNER JOIN dbo.casemain ON dbo.casereslist.casemain_id = dbo.casemain.casemain_id INNER JOIN dbo.caseintraop ON dbo.casemain.casemain_id = dbo.caseintraop.casemain_id INNER JOIN dbo.anestypelist ON dbo.casemain.casemain_id = dbo.anestypelist.casemain_id INNER JOIN dbo.resrole ON dbo.casereslist.resrole_id = dbo.resrole.resrole_idWHERE (dbo.resrole.name = 'ANESTHESIOLOGIST') OR (dbo.resrole.name = 'CERTIFIED REGISTERED NURSE ANESTHETIST')
Thats because you have more than one record per patient in any of the involved tables. can you post same data of a single patient from each of tables so as determine this? |
 |
|
|
|
|
|
|
|