i have 2 tables.the first contains lastname,phone1,adress,etc...the second contains firstname,phone1. I want to insert the firstname from the second table into the first table where phone1 one is identical.
thank you..Do you want to insert a new row or update an existing row?|||Originally posted by r123456
Do you want to insert a new row or update an existing row?
thank you for your reply
i want to update the row.
Your statements add and unfortunatelly dont make all the comparisons,though the compared fields are of the same data type|||update table2
set firstname =
(select firstname
from table1 t1
where key = t1.key);|||Originally posted by r123456
update table2
set firstname =
(select firstname
from table1 t1
where key = t1.key);
ANALYSER'S MSG
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
thank you|||You need to join the tables on a candidate key. If you replaced key with 'phone' then the query is returning multiple phone numbers meaning a phone number is not unique. Join on the primary key as this will ensure only a single row is returned.|||Originally posted by r123456
You need to join the tables on a candidate key. If you replaced key with 'phone' then the query is returning multiple phone numbers meaning a phone number is not unique. Join on the primary key as this will ensure only a single row is returned.
i set [phone] as primary key and is accepted.
Although the querry doesnt write all the fields i selected in my table
.... it seems it doesnt make the comparison.
thank you.|||Select *
from table1 t1
INNER JOIN
table2 t2 ON
t1.phone = t2.phone;
If this does not return macthing rows then the data types of phone in both tables are not identical;|||Originally posted by r123456
Select *
from table1 t1
INNER JOIN
table2 t2 ON
t1.phone = t2.phone;
If this does not return macthing rows then the data types of phone in both tables are not identical;
thanks a lot for your help
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment