Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I select insert to mysql but modify values manually?

Tags:

mysql

insert into 
 keyword_history (
   keyword_id, 
   searchengine, 
   location, 
   "4", 
   curdate()
   ) 
 select 
  keyword_id, 
  searchengine, 
  location 
 from 
  keyword_history 
 where 
  history_id = 21

Basically, what I'm trying to do is :

  1. select a row from a table
  2. insert it again but this time with current date and the value "4"
like image 720
vick Avatar asked Dec 12 '22 20:12

vick


2 Answers

Yes you can. You may want to try the following instead:

INSERT INTO keyword_history 
(
   keyword_id, 
   searchengine, 
   location, 
   rec_date, 
   currentrank
) 
SELECT  keyword_id, 
        searchengine, 
        location,
        curdate(),
        '4' 
FROM    keyword_history 
WHERE   history_id = 21;

EDIT: Updated field names as per comment below.

like image 103
Daniel Vassallo Avatar answered Feb 16 '23 09:02

Daniel Vassallo


Try this; it seems you're putting values in your field list inadvertently...

insert into keyword_history 
  (keyword_id, searchengine, location, your_number_col, your_date_col) 
select keyword_id, searchengine, location, '4', curdate()
from keyword_history 
where history_id = 21
like image 37
Tahbaza Avatar answered Feb 16 '23 09:02

Tahbaza