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 |
|
Caz1224
Starting Member
2 Posts |
Posted - 2009-09-13 : 18:45:26
|
| Hi there,The line I am trying to run is to combine 3 tables on a primary key of "patient_id" The three tables are patientpat_detailsrec_locationBelow is my code...SELECT * FROM pat_details INNER JOIN patient ON pat_details.patient_id = patient.patient_idJOIN pat_details ON pat_details.patient_id = rec_location.patient_idAnd the error:Msg 1013, Level 16, State 1, Line 1The objects "pat_details" and "pat_details" in the FROM clause have the same exposed names. Use correlation names to distinguish them.Help!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2009-09-13 : 23:36:43
|
| Your second join has pat_details repeated, which it doesn't sound like you want to do. If you do want to join to pat_details twice, then you'll need to alias them (hence the error).Here is probably what you want:SELECT * FROM pat_details JOIN patient ON pat_details.patient_id = patient.patient_idJOIN rec_locationON pat_details.patient_id = rec_location.patient_idTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog"Let's begin with the premise that everything you've done up until this point is wrong." |
 |
|
|
Caz1224
Starting Member
2 Posts |
Posted - 2009-09-15 : 23:41:11
|
| Thank you soooo muchly that worked a treat! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-17 : 02:11:25
|
| Also explicitely type the column names as there is high chance of having duplicate columns when you use *MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|