| Ok, I changed test query to: select min(pb.metalHeight), pd.pot.room.smelter.name from PotDates pd left join PotBath pb on pb.potDates.pot.room.smelter.smelterId = pd.pot.room.smelter.smelterId and pb.potDates.pot.room.roomId = pd.pot.room.roomId and pb.potDates.pot.potId = pd.pot.potId and pb.potDates.date = pd.date group by pd.pot.room.smelter.name and the resulting SQL still contains unnecessary left join and moreover it's not valid anymore, because it's trying to use table which is defined later in previous joins like this:
and the condition in PotBath join is very strange. It should reference the table itself but is using other tables in join condition |