SELECT 
	${table}.*,
	${table}_log.operation,
	${table}_log.status,
	${table}_log.date
FROM 
	${table}, 
	${table}_log,
	(SELECT ${idField}, max(date) AS maxdate 
		FROM ${table}_log 
		GROUP BY ${idField}) AS TAB 
WHERE 
	TAB.maxdate = ${table}_log.date AND
  	TAB.${idField} = ${table}_log.${idField} AND 
  	TAB.${idField} = ${table}.${idField}
  	#if (${from})
  		AND ${table}_log.date >= '${from}'
  	#end
  	#if (${until})
  		AND ${table}_log.date <= '${until}'
  	#end
ORDER BY ${table}_log.date;
