Missing Data

It is possible that we did not have some of the data when we create a record. For instance we may not have the birth date, or gender. Now we want to find all of the records where the gender or birthdate is missing;
SELECT * FROM Patients WHERE Gender IS NULL OR birthdate IS NULL

JOIN

We have a table called patients and another table called Diseases. We want to know what diseases each patient has. Notice that Patients has as its primary key a field called Patient that is an integer with auto increment. If you enter the query SHOW COLUMNS FROM Diseases you will see the output as shown below:

FieldTypeNullKeyDefaultExtra
IDint(11)NOPRI0
diseasevarchar(30)NOPRI

Count=2

There are a few ways to find out which disease belong to each person.

SELECT * FROM Patients LEFT JOIN Diseases ON Patients.patient=Diseases.ID will show all of the Patients with a separate row for each disease they have.

SELECT * FROM Patients,Diseases WHERE Patients.patient=Diseases.ID will show only those patients who have a disease. There will be a separate row for each disease.

SELECT * FROM Patients,Diseases WHERE Patients.patient=Diseases.ID AND disease="cancer" Will show all of the patients who have cancer.

SELECT * FROM Patients LEFT JOIN Diseases ON Patients.patient=Diseases.ID WHERE disease="cancer" Will also show all of the patients who have cancer.


INDEX, Retrieving Records with PHP, Add, Update and Delete, Missing Data, Join Tables, ALTER Table
Next lesson: FormsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Missing Data, Join Tables