I am trying to insert a new record if the email address does not exist in list_email.email_addr AND not exist in list_no_email.email_addr
INSERT INTO list_email
INSERT INTO list_email
(fname, lname, email_addr)
SELECT ins.*
FROM
( SELECT 'bob' AS fname,
'schmoe' AS lname,
'bogus@bogus.com' AS email_addr
FROM dual
UNION ALL -- for every row to be inserted
SELECT 'mary', 'lamb', 'hoe@me.com'
FROM dual
-- add another UNION ALL .. FROM dual
) AS ins
WHERE NOT EXISTS
( SELECT 1
FROM email_addr AS e
WHERE e.email_addr = ins.email_addr
)
AND NOT EXISTS
( SELECT 1
FROM list_no_email AS ne
WHERE ne.email_addr = ins.email_addr
) ;
Replace
WHERE NOT EXIST(
With
WHERE email_addr NOT IN(
EDIT
Replace
SELECT email_addr FROM list_email
WHERE NOT IN
(
SELECT email_addr FROM email_addr WHERE email_addr = $post_addr
)
WHERE NOT IN
(
SELECT email_addr FROM list_no_email WHERE email_addr = $post_addr
)LIMIT 1
with
SELECT email_addr FROM list_email
WHERE NOT IN
(
SELECT email_addr FROM email_addr WHERE email_addr = $post_addr
UNION ALL
SELECT email_addr FROM list_no_email WHERE email_addr = $post_addr
)
LIMIT 1
Try something like this:
INSERT INTO list_email($username.$rowname, fname, lname, list_email) VALUES(?,?,?,?,?)
SELECT email_addr FROM list_email AS tmp
WHERE email_addr NOT IN(
SELECT email_addr FROM list_email WHERE email_addr = $post_addr)
WHERE email_addr NOT IN (SELECT email_addr FROM list_no_email
WHERE email_addr = $post_addr)
LIMIT 1;