How to copy the values ​​of all id from the post table into the news_id field of the news_id table that is larger than the maximum news_id table. Those. copy without duplicates.

So it just goes copying:

 insert into `post_ex` (`news_id`) select `post`.`id` from `post` 

How to enter a condition to copy only those values ​​that are not yet?

  • The conditions "which are greater than the maximum news_id of the post_ex table" and "Copy without duplicates" are not at all the same. Describe the task again. - Get
  • Without duplicates. But already helped on another resource. Solution: insert into post_ex ( news_id ) select post . id from post where not exists (select 1 from post_ex where news_id = post.id) - Proff

1 answer 1

Reply from comments:

 INSERT INTO post_ex (news_id) SELECT post.id FROM post WHERE NOT EXISTS (SELECT 1 FROM post_ex WHERE news_id = post.id)