lacee1986
3/28/2017 - 10:10 AM

Select unique emails from 2 different table and order by date.

Select unique emails from 2 different table and order by date.

SELECT * FROM
(SELECT 
	CONCAT_WS(" ", C.NAME, C.SURNAME) AS 'Person Name',
	C.EMAIL AS 'Email Address',
	B.DATE AS 'Date they Subscribed'
	FROM CUSTOMERS C LEFT JOIN BOOKINGS B ON (C.CUS_ID=B.CUSTOMERS_ID) 
	WHERE C.MAIL_LIST_YN = 'Y' AND B.DATE>='2016-09-01' AND B.DATE<='2017-03-01'
	GROUP BY C.EMAIL
UNION
SELECT 
	N.NAME AS 'Person Name',
	N.EMAIL AS 'Email Address',
	N.DATE AS 'Date they Subscribed'
	FROM FORM_NEWSLETTER N 
	WHERE N.DATE>='2016-09-01' AND N.DATE<='2017-03-01'
	GROUP BY N.EMAIL
)
AS results
ORDER BY results.`Date they Subscribed` ASC