Exercises
Getting Started
In these exercises we will be using a database of that contains information about experiments: experiments.sqlite. We’ve put up instructions on how to use SQL Manager for Firefox to interact with this database.
The exercises
In these exercises we use a different database than the previous exercises. The database contains three tables which track data about the projects and their experiments being conducted in a laboratory, and the scientists involved.
Person— has an entry for each scientist in the lab.Experiment— has an entry for each project and experiment id.ExperimentDetails— has an entry for each project, and experiment and lists other details about the project itself.
- Display all of the information from both the
ExperimentandExperimentDetailtable for each experiment. That is, match rows where the “Project” field is the same.
(Click for our answer)SELECT *
FROM Experiment
JOIN ExperimentDetail
ON Experiment.Project = ExperimentDetail.Project; - Again, join the
Experimenttable with theExperimentDetailtable, returning only the rows where “Project” field is the same. This time though, use the alias “e” for theExperimenttable, and “ed” for theExperimentDetailtable.
(Click for our answer)SELECT * FROM Experiment e JOIN ExperimentDetail ed ON e.Project = ed.Project;
- Again, using aliases, join the
Experimenttable with theExperimentDetailtable, returning only the rows where “Project” field is the same. This time, only fetch the “LoginID” and “Project” fields from theExperimenttable, and the “ExperimentName” field fromExperimentDetail.
(Click for our answer)SELECT e.LoginID, e.Project, ed.ExperimentName FROM Experiment e JOIN ExperimentDetail ed ON e.Project = ed.Project;
- Join the
Person,Experiment, andExperimentDetailtables. Join thePersonandExperimenttables on the “LoginID” field, and theExperimentandExperimentDetailtables on the “Project” AND “Experiment” fields. Fetch all the fields, and use aliases for the tables.
(Click for our answer)SELECT * FROM Person p JOIN Experiment e ON p.LoginID = e.loginID JOIN ExperimentDetail ed ON (e.Project = ed.Project AND e.Experiment = ed.Experiment);

For Question 4, it seems like you can join the tables in any order, but the columns of the returned table will follow the order of the joining. For example, in the answer above, the first group of columns would be from Person, the second group from Experiment, and the last group from ExperimentDetail.