Hello.


If condition 'where the MOST RECENT answer is less than 30 days ago'

isn't the same as 'where some answer is less than 30 days ago' in your

case? I think they're equal. So the query is:



SELECT DISTINCT q.question

FROM questions q 

INNER JOIN answers a ON a.qid=q.id 

WHERE dateago > DATE_SUB(NOW(),INTERVAL 30 DAY);



And the definitions of my test tables:



mysql> show create table questions\G;

*************************** 1. row ***************************

Table: questions

Create Table: CREATE TABLE `questions` (

`id` int(11) NOT NULL auto_increment,

`question` char(255) default NULL,

PRIMARY KEY  (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1

1 row in set (0.00 sec)



mysql> show create table answers\G;

*************************** 1. row ***************************

Table: answers

Create Table: CREATE TABLE `answers` (

`id` int(11) NOT NULL auto_increment,

`qid` int(11) default NULL,

`answer` char(255) default NULL,

`dateago` timestamp NOT NULL default CURRENT_TIMESTAMP,

PRIMARY KEY  (`id`),

KEY `qid` (`qid`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1



mysql> select * from answers;

+----+------+--------+---------------------+

| id | qid  | answer | dateago             |

+----+------+--------+---------------------+

|  1 |    1 | NULL   | 2005-07-08 17:36:16 |

|  2 |    2 | NULL   | 2005-07-08 17:36:26 |

|  3 |    3 | NULL   | 2005-07-08 17:36:32 |

|  4 |    3 | NULL   | 2005-08-07 17:36:42 |

|  5 |    3 | NULL   | 2005-08-07 17:36:50 |

+----+------+--------+---------------------+



mysql> select * from questions;

+----+----------+

| id | question |

+----+----------+

|  1 | q1       |

|  2 | q2       |

|  3 | q3       |

+----+----------+









Brian Dunning <[EMAIL PROTECTED]> wrote:

> I have a table of questions, and a table of answers. Each question  

> has a related answer record for each person who has answered that  

> question, and each answer is timestamped. How do I find a list of  

> questions where the MOST RECENT answer is less than 30 days ago?  

> (Basically trying to exclude questions that nobody has answered  

> lately.) Thanks.  :)

> 



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to