A
A
Alexey Tolstoukhov2019-03-12 11:14:57
MySQL
Alexey Tolstoukhov, 2019-03-12 11:14:57

Transferring data from one table to another?

The crux of the matter is this.
There are three bases!
Two of which need to be added to one.
Each base has different columns.
1 base id, name, pass, type, email
2 base id, user, password, ip, email
3 base (To which you need to add the bases above) id, username, password, email, ip, db
How to implement it!?
For example, if there is no ip, email in 1 database, then null will be added
. Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2019-03-12
@leha2002828

You write "base" and actually the table?

INSERT INTO tbl3 (username, password, email, ip)
SELECT name, pass, email, null FROM tbl1

INSERT INTO tbl3 (username, password, email, ip)
SELECT user, password, email, ip FROM tbl2

If email is in the first and second, but with different name and ip, then you can make email a unique field, and insert the second table using on duplicate key update .

L
Lander, 2019-03-12
@usdglander

INSERT IGNORE INTO `base_3` (
    SELECT 
        `id` AS `id`, 
        `name` AS `username`, 
        `pass` AS `password`,
        `email` AS `email`,
        NULL AS `ip`, 
        NULL AS `db`
    FROM `base_1`
    UNION
    SELECT 
        `id` AS `id`, 
        `user` AS `username`, 
        `password` AS `password`,
        `email` AS `email`,
        `ip` AS `ip`, 
        NULL AS `db`
    FROM `base_2`
)

Something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question