BR
asked on
updating table data with inner join
Dear Experts,
I have two tables, both of them has the same coloumn name "cep" and user id which is uid ( user id ).
I want to update table a from table b since both tables have the same uid that I can use as a key
I use below statement however, it doesn't work since table a has additional uid entries.
table a has 520 uid, table b has 490 uid ( user id )
my question is: do I have to make both tables equal to get the data from table a to table b ? or is there a better way to do that?
Update Mytable a
inner join telefon b
on a.uid= b.uid
set a.cep = b.cep
I have two tables, both of them has the same coloumn name "cep" and user id which is uid ( user id ).
I want to update table a from table b since both tables have the same uid that I can use as a key
I use below statement however, it doesn't work since table a has additional uid entries.
table a has 520 uid, table b has 490 uid ( user id )
my question is: do I have to make both tables equal to get the data from table a to table b ? or is there a better way to do that?
Update Mytable a
inner join telefon b
on a.uid= b.uid
set a.cep = b.cep
ASKER
Dear Naitik,
thank you for the answer,
However there is an error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM
thank you for the answer,
However there is an error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM
Dear Braveheartli
If you are using through PHP code then may be it is syntax error....but it works fine in SQL server management studio directly.
If you are using through PHP code then may be it is syntax error....but it works fine in SQL server management studio directly.
Because that syntax is for SQL Server. It's not supported in MySQL.
>> it doesn't work since table a has additional uid entries.
@Braveheartli - Why do you say that? As long as the uid entries aren't duplicated, it should work fine. Does for me anyway.
Could you elaborate on how it's not working, ie are you getting an error?
>> it doesn't work since table a has additional uid entries.
@Braveheartli - Why do you say that? As long as the uid entries aren't duplicated, it should work fine. Does for me anyway.
Could you elaborate on how it's not working, ie are you getting an error?
ASKER
dear _agx_
I thought so, but it has below error
my first table has some additional entries. I mean the first table has
the error: #1265 - Data truncated for column 'isim' at row 4
first table has 520 rows and the other table has 490 rows
Update Mytable a
inner join telefon b
on a.uid= b.uid
set a.cep = b.cep
I thought so, but it has below error
my first table has some additional entries. I mean the first table has
the error: #1265 - Data truncated for column 'isim' at row 4
first table has 520 rows and the other table has 490 rows
Update Mytable a
inner join telefon b
on a.uid= b.uid
set a.cep = b.cep
Sounds more like the column being updated isn't big enough to store the new values. So the data is being truncated.
Check the datatype and size of the "cep" column in the two tables and make sure they're the same size.
Check the datatype and size of the "cep" column in the two tables and make sure they're the same size.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, You are right _agx_,
it was a perfect answer.
Thank you very much
it was a perfect answer.
Thank you very much
You're welcome. Glad it helped.
UPDATE Mytable SET Mytable.cep = telefon.cep FROM Mytable
INNER JOIN telefon ON telefon.uid = Mytable.uid