cheeseus Posted March 21, 2011 Share Posted March 21, 2011 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 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/ Share on other sites More sharing options...
The Little Guy Posted March 21, 2011 Share Posted March 21, 2011 the field parent doesn't exist in the table news_text Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190527 Share on other sites More sharing options...
cheeseus Posted March 21, 2011 Author Share Posted March 21, 2011 the field parent doesn't exist in the table news_text It does exist. I wouldn't be asking a question here if I wasn't sure it exists and yet I get this mistake. Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190530 Share on other sites More sharing options...
The Little Guy Posted March 21, 2011 Share Posted March 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190573 Share on other sites More sharing options...
cheeseus Posted March 21, 2011 Author Share Posted March 21, 2011 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". Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190604 Share on other sites More sharing options...
cheeseus Posted March 22, 2011 Author Share Posted March 22, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190617 Share on other sites More sharing options...
cheeseus Posted March 22, 2011 Author Share Posted March 22, 2011 RESOLVED: It appears I had to declare the table I was copying the data from in the UPDATE part: UPDATE news_text, news SET news_text.date = news.date WHERE news_text.parent = news.id Quote Link to comment https://forums.phpfreaks.com/topic/231318-copy-single-field-data-from-one-table-to-another-help/#findComment-1190745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.