I'm trying to execute a MySQL query by putting the email adresses in 3 different tables (oc_customer, oc_journal2_newsletter and oc_d_newsletter_subscriber) together. When all emails are put into 1 column, I want to group it to avoid duplicates and sort the data ascending.
I have the following query below, but each time I receive the message about the invalid token ')' before the query is effectively executed. The message is pointing to the line having the code .... subscribed
= '1')....
Can somebody help me out to avoid this warning?
SELECT `emailTOTAAL`.`emailTOT`
FROM (
SELECT
`oc_customer`.`email` AS `emailTOT`
FROM
`oc_customer`
WHERE
`oc_customer`.`language_id` = '2' AND
`oc_customer`.`newsletter` = '1'
UNION ALL
SELECT
`oc_journal2_newsletter`.`email` AS `emailTOT`
FROM
`oc_journal2_newsletter`
UNION ALL
SELECT
`oc_d_newsletter_subscriber`.`email` AS `emailTOT`
FROM
`oc_d_newsletter_subscriber`
WHERE
`oc_d_newsletter_subscriber`.`language_id` = '2' AND
`oc_d_newsletter_subscriber`.`subscribed` = '1')
AS `emailTOTAAL`
GROUP BY
`emailTOTAAL`.`emailTOT`
ORDER BY
`emailTOTAAL`.`emailTOT` ASC
Thanks, Vicef