Update values by another column in another table - mysql

I need a query to:
Copy from database player, table item_proto_0, column locale_name
Paste to database player, table item_proto, column locale_name
But:
Just paste if has the same colum vnum
I've tried:
UPDATE item_proto.locale_name
SET item_proto_0.locale_name
WHERE item_proto_0.vnum=item_proto.vnum

Try this:
UPDATE item_proto P1
JOIN item_proto_0 P2
ON P1.vnum = P2.vnum
SET P1.locale_name = P2.locale_name

This should work:
UPDATE item_proto AS ip
INNER JOIN item_proto_0 ip0 ON ip.vnum = ip0.vnum
SET locale_name = ip0.locale_name

Please run this sql query this should do the needful
UPDATE item_proto
inner join item_proto_0 on item_proto.vnum = item_proto_0.vnum
SET item_proto.locale_name = item_proto_0.locale_name

Related

How to update values in two tables where one is usermeta MySQL

I have two tables and I need to make single SQL request which will update values in both of them.
Their releation is based on ID (1 table = evdb_users.ID / 2 table = evdb_usermeta.user_id)
For now I did some SQL query like this:
"UPDATE evdb_users
INNER JOIN evdb_usermeta ON evdb_users.ID = evdb_usermeta.user_id AND evdb_usermeta.meta_key='phone_number'
SET evdb_users.user_login='%s', evdb_users.user_email='%s', evdb_users.display_name='%s', evdb_usermeta.meta_value='%s'
WHERE evdb_users.ID=%d"
Data in evdb_users (login/email/display name) - are updating, but nothing changes in usermeta (phone_number)
Please help me to figure out how it should be and how it must works.
try this:
UPDATE evdb_users
INNER JOIN evdb_usermeta
ON evdb_users.ID = evdb_usermeta.user_id
AND evdb_usermeta.meta_key='phone_number'
SET evdb_users.user_login='%s'
, evdb_users.user_email='%s'
, evdb_users.display_name='%s'
, evdb_usermeta.meta_value='%s'
WHERE evdb_users.ID=%d;

MySQL Update Database Command not Working

I now have a MySQL Command for Updating a Row of a MySQL Table with Values from another Table.
update info set info.artist = playlist.artist
from playlist
where info.songname = playlist.songname
There is an Syntax Error. But I can see anything in there.
1st Table
2nd Table
Thanks :)
Try this:
UPDATE info
INNER JOIN playlist ON info.songname = playlist.songname
SET info.artist = playlist.artist
2nd Sample:
UPDATE info
INNER JOIN (
SELECT songname, artist
FROM playlist
WHERE playlist.time_requested IS NOT NULL
ORDER BY playlist.time_requested
LIMIT 1
) PL ON info.songname = PL.songname
SET info.artist = PL.artist

Update column with data from another table's column

Let's say I have two tables in a MySQL database. I would like to update the data from a column in the source table to a column in the target table.
Source table is called 'Computers_F1' Source column is called 'Family'.
Target table is called 'Advice' Target column is called 'Fase1'
I want to put all the rows from 'Family' into 'Fase1'. But this without it adding new rows. I want all the information to be updated in the existing rows.
Hope you guys can help me!
You can do something like this if you have a column id to match both
UPDATE Advice AS a
SET Fase1 = (SELECT Family FROM Computers_F1 AS c WHERE a.id = c.id)
And then rename the column Fase1
ALTER TABLE Active CHANGE `Fase1` `Family` VARCHAR(255)
(replacing VARCHAR(255) with the right format of your column)
I know 2 ways:
UPDATE Advice, Computers_F1
SET Advice.Fase1 = Computers_F1.Family
WHERE Advice.Id = Computers_F1.Id;
OR
UPDATE Advice
INNER JOIN Computers_F1
ON Advice.Id = Computers_F1.Id
SET Advice.Fase1 = Computers_F1.Family;
Hope this helps...
UPDATE
Correct examples, with foreign keys:
UPDATE Advice, Computers_F1
SET Advice.Fase1 = Computers_F1.Family
WHERE Advice.Computers_F1_Id = Computers_F1.Id;
OR
UPDATE Advice, Computers_F1
SET Advice.Fase1 = Computers_F1.Family
WHERE Advice.Id = Computers_F1.Advice_Id;
OR
UPDATE Advice
INNER JOIN Computers_F1
ON Advice.Computers_F1_Id = Computers_F1.Id
SET Advice.Fase1 = Computers_F1.Family;
OR
UPDATE Advice
INNER JOIN Computers_F1
ON Advice.Id = Computers_F1.Advice_Id
SET Advice.Fase1 = Computers_F1.Family;

How to copy 3 columns from one table into another in mysql

I have two tables and both include 2 columns, sureness and kindness and and they are related to each other by dataitemID and id. Just to show you the structure I will put 2 selects that I got from database:
SELECT ID,sureness,kindness FROM omid.tweet ;
SELECT ID,DataitemID,sureness,kindness FROM omid.entity_epoch_data ;
and I want to copy all value of sureness and kindness in omid.tweet into entity_epoch_data where entity_epoch_data.entityID is equal to entityID coming from entity_relation where tweet.ID =entity_relation.ID
I want just to do it in mysql rather than reading the whole table in java and updating the database in the loop but I am so confused. How can I do that?I appreciate any help:)
Update:
I wrote the code as follow but it does not work:
update tweet, entity_epoch_data
set entity_epoch_data.sureness= tweet.sureness,
entity_epoch_data.kindness = tweet.kindness ,
entity_epoch_data.calmness = tweet.calmness ,
entity_epoch_data.happiness = tweet.happiness
WHERE entity_epoch_data.EntityID in(
SELECT EntityID FROM omid.entity_dataitem_relation
INNER JOIN omid.tweet t ON entity_dataitem_relation.DataitemID = t.ID)
It's actually pretty straight forward. The UPDATE clause works like a JOIN and then use SET to set the values
UPDATE tweet INNER JOIN entity_epoch_data
ON tweet.id = entity_epoch_data.id
SET entity_epoch_data.sureness= tweet.sureness,
entity_epoch_data.kindness = tweet.kindness

Update using Select Statement

I wanna write a query like this :
UPDATE `test_credit`
SET `test_credit`.`credit`=(`test_credit`.`credit`-((`test_credit`.`credit`/100)*5))
WHERE `test_credit`.`name` = `users`.`uname`
in fact i want to get a query on users.uname = test_credit.name but mysql say it has error and realize users.uname as column
what is correct query ?
You need to explicitly join it with table users. As far from my understanding based on your query, you want to calculate the credit if the names exists on both tables.
Give this a try,
UPDATE test_credit a
INNER JOIN users b
ON a.name = b.uname
SET a.credit = (a.credit - ((a.credit/100) * 5.0))
-- WHERE b.parent= "example"