But it prints too many records: all moves cross-multiplied with each other.As if I have forgotten to add 1 more condition to the JOIN LATERAL
LIMIT 1 inside your lateral should resolve that. Personally, I'd move that condition to EXISTS condition inside WHERE clause instead. Just a style thing as far as I know.