'Does the order of outer joins matter?
I have the following database:

My task is: For every class of British ships I want to get the names of all the battles that these ships have participated in. If a class does not have any ships or has some ships but none of them have participated in any battle, the result should have NULL in the column for the name of the battle.
I have a solution for this task(I use two left joins, but the problem is that when I try to write the query using right join the output is different, so I am not sure which one is correct.
These are the solutions:
select distinct classes.class, battle
FROM classes
LEFT JOIN ships ON ships.class = classes.class
LEFT JOIN outcomes ON ship = name
WHERE country = 'Gt.Britain'
select distinct classes.class, battle
from outcomes
join ships on ship = name
right join classes
on ships.class = classes.class
where country = 'Gt.Britain'
In my opinion they should return the same result, but that is not true. Can you tell me what is wrong here, I know that the order of outer joins matter but here I cannot understand what is wrong, they seem exactly the same to me. And is any of these solutions correct?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
