Retrieving Records From Multiple Tables With Joins in MySQL
MySQL·3 min read·Jan 1, 2025
A relational database consists of multiple related tables linked together by common attributes called relationships.
These relationships can be used to combine the data from multiple tables simultaneously in a single query through a mechanism called a join.
Setting up the database
Before diving into this lesson, you will have to perform some modifications on your database.
-
Add a new column named
manager_idto theemployeestable:mysql> ALTER TABLE employees ADD COLUMN manager_id INT NULL; -
Create a relationship between the
idcolumn and themanager_idcolumn:mysql> ALTER TABLE employees ADD CONSTRAINT fk_manager FOREIGN KEY (manager_id) REFERENCES employees(id); -
Update the records of the
employeestable:mysql> UPDATE employees SET manager_id = 9 WHERE id = 2;
Unlock the Build RESTful APIs in Node.js module
Learn how to build real database-backed and framework-powered RESTful APIs with MySQL, Sequelize, and Express.
You get immediate access to:
- 37 focused lessons across MySQL, Sequelize, backend, and Express
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle