Jump to content

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


cheeseus

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!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.