I have 2 tables - user, region and a join/connecting table that is used to join both user and region.
I need to insert into the join table all the region values that the user does not already have and i am unsure how to go about this.
I have attempted this numerous ways but i am not entirely sure how to only place the values that do already exist within the table into the join table. Does anyone have any ideas or suggestions?
SELECT
CONVERT( CONCAT('INSERT INTO user_region VALUES(',
user.id,
',',
reg.id,
');') USING UTF8)
FROM
user user
JOIN
user_region user_reg ON user_reg.id = user.id
JOIN
region reg ON reg.id = user_reg.id
WHERE
(user.email_address LIKE '%gmail%'
OR user.email_address LIKE '%hotmail%');
User Table User Region Region
----------- ----------- ------
1 1 2 1
2 3 2 2
3 3 4 3
4 4 3 4