SELECT * FROM tablename o WHERE key = ? AND version = ( SELECT max(version) FROM tablename i WHERE i.key = o.key )