Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update query

Status
Not open for further replies.

Queryman

Programmer
Nov 4, 2002
243
US
I have two tables
1. named "A" has three fields
pat_id (unique integer) and DOS (date field) & DOS2 which
is an empty date field
2. named "B" has two fields(Pat_id & DOS)

I am trying to update the field in table "A" called DOS2 so that it
would contain the date field from table "B"
update a_patient set DOS2 = b_patient.DOS where
a_patient.pat_id in (select pat_id from b_patient)


Even though I have unique pat_id's in both tables and all the pat_id's in table "A" are in table "B", I get a dulpicate row error in table "A" when trying to update.



Michael

 
Try this

update a_patient
from b_patient
set dos2=b_patient.dos
where b_patient.pat_id = a_patient.pat_id
 
Did you EXPLAIN it?
The correlation between the two tables is missing so you're trying to update a row with every value from the second table.

update a_patient from b_patient
set DOS2 = b_patient.DOS where
a_patient.pat_id = b_patient.pat_id

The "from b_patient" is optional in this case

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top