Create a table called item in your database using PHPMyAdmin:Fruit table

Put this userName and itemEaten data into the table using the Insert tab in PHPMyAdmin:

  1. fred, banana
  2. john, banana
  3. fred, apple
  4. fred, apple
  5. john, banana
  6. fred, apple

For some reason it records the fruit two people have eaten over the last few days.  I guess someone might want to!

Now open sqllist.php from beginnerssite and save it as sqldistinct.php in intermediatesite.  Change the database name (near the top) if you need to.  Change the existing SELECT query so that it extracts the userName and itemEaten from this new table instead of the current data.  Change the paragraph which says Current employees: (or whatever yours says) to Users have eaten this.  Save and try and you should see something like this:

Every item eaten by the people

Now change the query by adding the word DISTINCT before userName.  Now you only see unique entries in the table so you know who has ever eaten what.

The variety of items eaten

If you want to check for unique entries in just one field remove the other fields from the list in the query.  You could do this to list all users who have logged in recently (or in this case who have eaten fruit).