Jump to content

Copy single field data from one table to another - help?


Recommended Posts

Hello,

 

I am trying to copy the data from one of the columns of a table to a column of the same name in another table but can't seem to make it work.

 

The two tables have a different structure.

 

I am trying to copy the "date" field from "news" into the "date" field of "news_text".

 

INSERT INTO news_text (news_text.date) SELECT news.date FROM news WHERE news_text.parent = news.id

 

I get the following error:

#1054 - Unknown column 'news_text.parent' in 'where clause'

 

The "news.id" field corresponds to the "news_text.parent" field.

 

I can't figure out what I am missing  :-\

check you spelling, case, and make sure you are referring to the correct table. Other than that we can't really help you, if mysql can't find the column, it either doesn't exist, or your referring to the wrong table.

 

 

I tried this to test how this thing works (first time ever I need to copy data from one table to another).

 

So, now I tried this:

 

 INSERT INTO news_text (date) SELECT news.date FROM news 

 

This is supposed to copy ONLY the "date" field, isn't it? Now, it copies ALL the fields of that table.

 

Am I writing this correctly?

 

 

EDIT: Did some more reading and decided to try this:

UPDATE news_text1
INNER
  JOIN news
    ON news.id = news_text1.parent
   SET news_text1.date = news.date

 

This gets executed but "0 rows are affected".

:confused:

 

 

I also tried this:

UPDATE news_text1 SET news_text1.date = news.date WHERE news_text1.parent = news.id

 

I've noticed that whichever column I put after the equal sign is the "unknown column". I guess I'm making some some really stupid mistake or some is broken in my PhpMyAdmin. ...

 

Help please!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.