Mysql insert into with multiple id from another table

Jean-philippe Emond

I have 2 table, first I retrieve all Ids like this:

select DISTINCT entity_id From table1

I want to create a bulk insert using entity_id and prevent duplicate if the entity_id have a specifique value in the colomn2:

example

    *********************************************
    *  ID   *  ENTITY_ID *  COLOMN2 *  value    *
    *********************************************
    *  1    *     230    *    20    *    1      *
    *  2    *     230    *   100    *    1      *
    *  3    *     280    *    20    *    0      *
    *  4    *     220    *    20    *    1      *
    *********************************************
    select DISTINCT entity_id From table1 // return : 230,280,220


    INSERT into table1 ('ENTITY_ID','COLOMN2','VALUE') VALUES([the select id],100,1) 
    WHERE COLOMN2<>100

or something like that?

the result need to be:

creating 2 insert... entity_id=220 and entity_id=280

with the colomn2=100 and value = 1

any idea ?

Sam

Use a subquery

INSERT INTO table1 ('ENTITY_ID','COLOMN2','VALUE')
(select DISTINCT entity_id ,100,1 FROM table2 WHERE column2<>100) 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

insert multiple rows mysql from another table

From Dev

MySQL - Insert into a table by querying product id from another table

From Dev

MySql: insert into table SELECT from another table where first_table ID =another_table.id

From Dev

MySQL insert into a table from multiple table filter by id

From Dev

Insert ID from one table to another in MySQL php

From Dev

Insert OUTPUT Insert.id to another table in multiple values insert

From Dev

MySQL - Insert table data from another table

From Dev

MySQL - Insert table data from another table

From Dev

Multiple insert in MySQL table from PHP table

From Dev

Multiple insert in MySQL table from PHP table

From Dev

insert from another table and then link tables by id

From Dev

insert an id gotten from another table

From Dev

insert an id gotten from another table

From Dev

mysql, java - Get last inserted auto increment id from one table and insert it again on another table

From Dev

Insert multiple rows from select into another table

From Dev

How to insert multiple rows from a table to another table based on date condition (PHP-MySQL-Query)?

From Dev

Select multiple columns from a table and insert data into another table in a different database in PHP-MySQL

From Dev

looping mysql query to get multiple rows of data from a table and insert into another table

From Dev

How to insert multiple records from one table into another on update of third table in MySQL

From Dev

Mysql insert column from another table

From Dev

MySQL insert into column data from another table

From Dev

Insert Data From One Table To Another - MySQL

From Dev

Mysql query insert from another table

From Dev

mysql insert into table select from another database

From Dev

How to insert multiple rows into one table for each id of another table

From Dev

how to insert data from another table with id from my table

From Dev

Insert multiple rows into a MySQL database from a table

From Dev

MySql Retrieving Data from multiple Tables then Insert limited values In another table

From Dev

Insert id's from one table to another based on another column

Related Related

  1. 1

    insert multiple rows mysql from another table

  2. 2

    MySQL - Insert into a table by querying product id from another table

  3. 3

    MySql: insert into table SELECT from another table where first_table ID =another_table.id

  4. 4

    MySQL insert into a table from multiple table filter by id

  5. 5

    Insert ID from one table to another in MySQL php

  6. 6

    Insert OUTPUT Insert.id to another table in multiple values insert

  7. 7

    MySQL - Insert table data from another table

  8. 8

    MySQL - Insert table data from another table

  9. 9

    Multiple insert in MySQL table from PHP table

  10. 10

    Multiple insert in MySQL table from PHP table

  11. 11

    insert from another table and then link tables by id

  12. 12

    insert an id gotten from another table

  13. 13

    insert an id gotten from another table

  14. 14

    mysql, java - Get last inserted auto increment id from one table and insert it again on another table

  15. 15

    Insert multiple rows from select into another table

  16. 16

    How to insert multiple rows from a table to another table based on date condition (PHP-MySQL-Query)?

  17. 17

    Select multiple columns from a table and insert data into another table in a different database in PHP-MySQL

  18. 18

    looping mysql query to get multiple rows of data from a table and insert into another table

  19. 19

    How to insert multiple records from one table into another on update of third table in MySQL

  20. 20

    Mysql insert column from another table

  21. 21

    MySQL insert into column data from another table

  22. 22

    Insert Data From One Table To Another - MySQL

  23. 23

    Mysql query insert from another table

  24. 24

    mysql insert into table select from another database

  25. 25

    How to insert multiple rows into one table for each id of another table

  26. 26

    how to insert data from another table with id from my table

  27. 27

    Insert multiple rows into a MySQL database from a table

  28. 28

    MySql Retrieving Data from multiple Tables then Insert limited values In another table

  29. 29

    Insert id's from one table to another based on another column

HotTag

Archive