DROP TABLE IF EXISTS DOMAIN_LOG;

CREATE TABLE DOMAIN_LOG(
  LOG_ID INT NOT NULL auto_increment,
  DOMAIN_ID INT NOT NULL,
  LOGDATE DATE,
  VALUE VARCHAR(256),
  PRIMARY KEY(LOG_ID)
);


DROP TABLE IF EXISTS DOMAINS;

CREATE TABLE DOMAINS (
  DOMAIN_ID INT NOT NULL auto_increment,
  REGDATE DATE,
  PRIMARY KEY(DOMAIN_ID)
);

INSERT INTO DOMAINS SET REGDATE=DATE_SUB(NOW(), INTERVAL 6 DAY);

# INSERT HERE DATA THAT WILL MAKE THE SUBQUERY CRASH
# SET CORRECTLY THE LEFT EXPRESSION OF NOT IN BELOW
# (IE REPLACE .$welcome_desc.)

SELECT *
FROM DOMAINS
WHERE DATE_ADD(REGDATE, INTERVAL 5 DAY) < NOW()
AND 'f' NOT IN (
SELECT VALUE FROM DOMAIN_LOG
WHERE DOMAIN_LOG.DOMAIN_ID=DOMAINS.DOMAIN_ID 
AND LOGDATE > DOMAINS.REGDATE
);

