fix queries using max(timestamp) as nested join