select multiple column from one table and insert into another as rows

Asadullah Khan Rind

I have two tables users and emails:

USER
+--------+-------+--------+--------+
| id (PK)| email | email2 | email3 |
+--------+-------+--------+--------+

EMAIL
+---------+--------------+---------------+
| id (PK) | user_id (FK) | email_address | 
+---------+--------------+---------------+

I need to select emails from users table and insert them into emails table as rows.

TheProvost

If your email table id has identity i would do it like this

INSERT INTO email (userid,email_address)
SELECT id, email  FROM user
UNION SELECT id, email2  FROM user
UNION SELECT id, email3 FROM user

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 from select into another table

From Dev

INSERT rows multiple times based on a column value from another table

From Dev

Insert multiple rows with single a query from one table into another in Oracle

From Dev

insert multiple rows mysql from another table

From Dev

Insert multiple rows in one table based on number in another table

From Dev

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

From Dev

How to select data from one table and insert it into another table with a new column

From Dev

How can i use SQL Select Insert to copy rows from one table to another

From Dev

Extract one column from sql table and insert into another table as multiple records coupled with different values

From Dev

select data from one column based on another column's condition in the same table and insert that resulting data to another table

From Dev

MySQL - Select multiple rows from one table whose IDs are stored in another table

From Dev

Insert many rows from a table into one unique row in another table

From Dev

Insert (multiple) new rows into a table from another table using a subquery?

From Dev

Insert in SQL table using select with column values from another select

From Dev

Select / Update records in one table that are LIKE words selected from another table column with multiple records

From Dev

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

From Dev

select from one table, insert into another table oracle sql query

From Dev

mysql insert unique values from one column to a column of another table

From Dev

insert data from one table to a single column another table with no relation

From Dev

Select rows from a table if one of them matches with another table

From Dev

Insert Data from one table to another leaving the already existing rows

From Dev

Insert specific rows from one table in database into another with different columns

From Dev

SQL insert multiple rows from single field in another table

From Dev

Sqlalchemy single query for multiple rows from one column in one table

From Dev

Calculating the value of multiple rows in a column from one table into an other table

From Dev

Calculating the value of multiple rows in a column from one table into an other table

From Dev

Insert multiple rows from two tables into one table

From Dev

MariaDB: Select the fields from one column in one table that are not in a subset of another column from another table

From Dev

Select from one table and order by column of another table

Related Related

  1. 1

    Insert multiple rows from select into another table

  2. 2

    INSERT rows multiple times based on a column value from another table

  3. 3

    Insert multiple rows with single a query from one table into another in Oracle

  4. 4

    insert multiple rows mysql from another table

  5. 5

    Insert multiple rows in one table based on number in another table

  6. 6

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

  7. 7

    How to select data from one table and insert it into another table with a new column

  8. 8

    How can i use SQL Select Insert to copy rows from one table to another

  9. 9

    Extract one column from sql table and insert into another table as multiple records coupled with different values

  10. 10

    select data from one column based on another column's condition in the same table and insert that resulting data to another table

  11. 11

    MySQL - Select multiple rows from one table whose IDs are stored in another table

  12. 12

    Insert many rows from a table into one unique row in another table

  13. 13

    Insert (multiple) new rows into a table from another table using a subquery?

  14. 14

    Insert in SQL table using select with column values from another select

  15. 15

    Select / Update records in one table that are LIKE words selected from another table column with multiple records

  16. 16

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

  17. 17

    select from one table, insert into another table oracle sql query

  18. 18

    mysql insert unique values from one column to a column of another table

  19. 19

    insert data from one table to a single column another table with no relation

  20. 20

    Select rows from a table if one of them matches with another table

  21. 21

    Insert Data from one table to another leaving the already existing rows

  22. 22

    Insert specific rows from one table in database into another with different columns

  23. 23

    SQL insert multiple rows from single field in another table

  24. 24

    Sqlalchemy single query for multiple rows from one column in one table

  25. 25

    Calculating the value of multiple rows in a column from one table into an other table

  26. 26

    Calculating the value of multiple rows in a column from one table into an other table

  27. 27

    Insert multiple rows from two tables into one table

  28. 28

    MariaDB: Select the fields from one column in one table that are not in a subset of another column from another table

  29. 29

    Select from one table and order by column of another table

HotTag

Archive