Save sqljoin.php as sqljoinouter.php.
The JOIN you have just done is technically known as an inner join. It joins data from both tables where there is data existing in both tables. Load sqljoinouter.php in your browser and it should have six results listed. Now use PHPMyAdmin to delete one value from the ref column:
- open the Browse tab of the appointment table
- click on the pencil to edit the third record
- delete the employeeID value and press Go
Refresh sqljoinouter.php and you should see just five results as there is one appointment which does not have any matching records in the employees table. As the JOIN cannot find data on the right side of the join (employees) to match the data on the left it does not find or display either.
If you want to show data where there is no matching data in the second table you change JOIN to LEFT OUTER JOIN. Try that. You should have six results again.
Note that the employees will appear as many times as they have appointments. If they have no appointments they do not appear. The LEFT command says to show all records from the table on the left side of the JOIN in the query. The things on the right are only shown if they are mentioned in the table on the left.
Instead you might want to show all employees in the list even where they do not have appointments. This may not be likely in this example but in other situations it can be useful. Try it with this page anyway by changing LEFT to RIGHT. Change it back after testing.
As with lots of things this will probably become important later on but for now just remember the principles.