Reputation: 9293
In both tables I have a column named date
(datetime - current timestamp).
I need to copy the first 20 values of that column from table posts
to table banners
.
insert into banners set date SELECT date FROM posts WHERE id < 21;
update banners set date SELECT date FROM posts WHERE id < 21;
In both cases I have an error:
Column count doesn't match value count at row 1
What does it mean this error and how I can copy the values?
Upvotes: 1
Views: 45
Reputation: 11556
Use JOIN
with UPDATE
.
Query
update `banners` t1
from `posts` t2
on t1.`id` = t2.`id`
set t1.`date` = t2.`date`
where t2.`id` < 21;
Upvotes: 1