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:The ID deleted

  1. open the Browse tab of the appointment table
  2. click on the pencil to edit the third record
  3. 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 the do not have appointments.  Maybe not 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.