Is it possible to embed in mysql but change the values ​​manually?

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

Basically, I am trying to do the following:

  • select row from table
  • insert it again, but this time with the current date and a value of "4"
+4
source share
2 answers

Yes, you can. Instead, you can try the following:

 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 according to the comments below.

+12
source

Try it; it seems like you are putting values ​​in your list of fields 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 
+1
source

Source: https://habr.com/ru/post/1315251/


All Articles