Writing queries and trying to do GROUP BY of the LEFT OUTER JOIN, might give you a headache such as “group by is not allowed”.
If this is the case for you try something like this. MAX(..) can be replaced witrh the other functions that works for you.
Might not be the best from perfomance point of view but works.

SELECT q.question, q.question_id, a.answer       
FROM questions q 
	SELECT answer, question_id
	FROM answers
	WHERE answer_date > .... AND groupby_column = (
	            SELECT MAX(groupby_column) 
	            FROM answers
	            WHERE question_id = q.question_id
) a ON a.question_id = q.question_id
WHERE ....

Dima Svirid

Software architect, JAVA, Spring, Hibernate, AngularJs, Backbone, MongoDB, Oracle. CTO and Co-Founder of Homeadnet.com

More Posts

Follow Me: