With the following query I am trying to get records from the week exactly one year ago to send them a remider to upgrade a product.
This works fine. Now I have to limit this query to the records which do not have a younger (<365) record with the same username/firstaname .
when I try this wth a "NOT IN" term, I can query only one operand (either name or first name) but I have to compare them in combination because the table is not perfectly normalized
- Code: Select all
SELECT A.id, A.datum, A.kundenname, A.vorname, A.email, B.email AS partnermail
FROM table_one AS A
INNER JOIN users AS B ON B.UserName = A.owner
WHERE TO_DAYS( NOW( ) ) - TO_DAYS( datum ) >=365
AND TO_DAYS( NOW( ) ) - TO_DAYS( datum ) <=372
AND A.kundenname NOT
IN (
SELECT kundenname
FROM table_one
WHERE TO_DAYS( NOW( ) ) - TO_DAYS( datum ) <365
)
Any Ideas are welcome
Cheers
Martin