Hi community,
I have Table 1 and Table2 both having unique emails within them.
Table 1 being the main email Container, I want INTERSECTION of Table 1 and Table2 and the UNIQUE emails between the two should be moved to Table 1.
So now that Table 1 should have All the Unique Emails within itself and also between Table 1 and Table2
ex
Table 1
A
B
C
D
Table 2
F
G
I
B
C
So finally Table 1 should have
A
B
C
D
F
G
I
Note: values B and C already exist in Table 1 and should be ignored.
How to write this query?
Merging Unique emails from 2 tables
Moderator: General Moderators
Re: Merging Unique emails from 2 tables
Not very efficient and my not work under mysql.
Code: Select all
SELECT DISTINCT
TABLE_A.EMAIL
FROM
TABLE_A,
WHERE
TABLE_A.EMAIL NOT IN (
SELECT DISTINCT
TABLE_B.EMAIL
FROM
TABLE_B
)
)
UNION SELECT DISTINCT
TABLE_B.EMAIL
FROM
TABLE_B,
WHERE
TABLE_B.EMAIL NOT IN (
SELECT DISTINCT
TABLE_A.EMAIL
FROM
TABLE_A
)
)
Re: Merging Unique emails from 2 tables
Hi,
the query
Doesn't seem to work
the query
Code: Select all
(SELECT DISTINCT
invites.email
FROM
invites,
WHERE
invites.email NOT IN (
SELECT DISTINCT
invites_test.email
FROM
invites_test
)
)
UNION (SELECT DISTINCT
invites_test.email
FROM
invites_test,
WHERE
invites_test.email NOT IN (
SELECT DISTINCT
invites.email
FROM
invites
)
)Re: Merging Unique emails from 2 tables
Try executing eveything before the union statement
Re: Merging Unique emails from 2 tables
Issue solved with the following code
Thanks
Code: Select all
INSERT INTO invites
SELECT invites_test.*
FROM invites_test
LEFT OUTER JOIN invites
ON invites.email = invites_test.email
WHERE invites.email IS NULL