I have a table of machines, and a table representing the reachability if these machines across time.
machines
id name
1 machine1
2 machine2
3 machine3
4 machine4
machines_reachability
machine_id is_reachable time
1 0 (whatever)
2 1 (whatever)
3 0 (whatever)
1 1 (whatever)
2 0 (whatever)
3 0 (whatever)
1 1 (whatever)
2 1 (whatever)
3 1 (whatever)
I'm trying to find machines that has NO reachability records (i.e. machine4) using JOINS. This can be done in another ways but I need to do this through joins to have a better understanding of it.
I tried the following
SELECT * FROM machines m LEFT OUTER JOIN machines_reachability mr ON m.id = mr.machine_id
I understand that this should output the whole left table contents (i.e. machines) and the OUTER
keyword should exclude the intersection of results between machines
and machines_reachability
tables based on the condition m.id = mr.machine_id
. But that didn't work as I expected. It showed all contents but didn't exclude the rows that didn't match.
So how can I run a JOIN
query that actually shows the rows that didn't join whether it's the left table or the right one selectively.