Text ...
In order to run this project, you have to either set up environment variables for your database or provide them as parameters to the Connect class.
ACADEMY_MYSQL_USERNAME- the username used to connect to the databaseACADEMY_MYSQL_PASSWORD- the password used to connect to the databaseACADEMY_MYSQL_HOST(optional, default127.0.0.1) - the MySQL server addressACADEMY_MYSQL_PORT(optional, default3306) - the MySQL server portACADEMY_MYSQL_DATABASE(optional, defulatacademy) - the name of the MySQL database
One entry in the courses table consists of a number of lessons. Example of courses inside the system:
- Python Core Programming
- Python Databases and SQL
- Python Object Oriented Programming etc.
One entry in the teachers table stores a person that teaches courses.
One entry in the cars table stores a car, which belongs to an entry in the teachers table.
One entry in the students tables stores a student that learns courses.
| id_student | id_course |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 2 | 4 |
| 3 | 1 |
| 3 | 4 |
One (1) teachers owns one (1) cars.
Select all teachers with cars and the details about their cars.
With native INNER JOIN:
SELECT t.id AS id_teacher, t.first_name, t.last_name, t.start_date, t.end_date, c.plate
FROM teachers AS t JOIN cars AS c ON t.id_car=c.id
With SELECT ... WHERE:
SELECT t.id AS id_teacher, t.first_name, t.last_name, t.start_date, t.end_date, c.plate
FROM teachers AS t, cars AS c WHERE t.id_car = c.id
Select all teachers who currently work in the academy (they don't have and end_date). For those who have a car, select details about their cars.
SELECT t.id id_teacher, t.first_name, t.last_name, t.start_date, t.end_date, c.plate
FROM teachers t LEFT OUTER JOIN cars c ON t.id_car=c.id
WHERE t.end_date IS NULL
Select all cars. For those who have a teacher, select details about their teachers.
SELECT c.plate, t.first_name, t.last_name, t.start_date, t.end_date, t.id id_teacher
FROM teachers t RIGHT OUTER JOIN cars c ON t.id_car=c.id
One (1) teachers teaches multiple (n) courses.
Multiple (n) students attend multiple (n) courses.