You haven't understand. I need to transform the first code. The second code was just an example, it's not the same algorithm and hasn't any problem. The second one works fine. The first code needs to be transformed using LEFT JOIN.

Jacques1: Of course I tried, but it seems that I've did some mistakes in the transformed code.