1

Originally I had to get the ip from old table and place it into the new table where the emails match in both.

INSERT INTO new (ip)
SELECT old.ip 
FROM old
INNER JOIN new on old.email = new.email;

I now need to change this query to do the following:

Get ip from old table
Match it the email from that row in the new table
Get the user_id from new table
Create a record in combined table with user_id and ip

Query so far:

Is this close? Doesn't seem right :/

comb_uid = SELECT old.ip FROM old  
WHERE new.email = old.email

comb_ip = SELECT new.user_id FROM new  

INSERT INTO combined (user_id, ip)
VALUES comb_uid, comb_ip 
4

1 に答える 1

0

あなたは十分に近かった。に変更newするだけcombinedです。

INSERT INTO combined (ip, user_ID)
SELECT  old.ip, new.user_ID
FROM    old
        INNER JOIN new 
            on old.email = new.email;

更新 1

INSERT INTO combined (ip, user_ID, status)
SELECT  old.ip, new.user_ID, 'approved'
FROM    old
        INNER JOIN new 
            on old.email = new.email;
于 2013-02-18T13:43:05.627 に答える