![]() Scenario 1 worked, but we didn't accomplish our goal. But our main goal is missing (that is, to get all the employee details) as we’re missing Sophia Ashley’s details. Great! □ Now we are able to retrieve employee details as well as their corresponding projects. (SELECT e.Id, e.FirstName, e.LastName, e.Designation, e.City, ep.ProjectId Let’s do that: SELECT abc.FirstName, abc.LastName, abc.City, abc.Designation, p.Name AS Project FROM Project AS p With the help of Employee-EmployeeProject, we’ll be able to access the Project table. It contains all the employee details as well as their corresponding project ids. ![]() Let’s think of the above table as Employee-EmployeeProject. Let’s go with INNER JOIN everywhere! SELECT e.Id, e.FirstName, e.LastName, e.Designation, e.City, ep.ProjectIdįROM Employee AS e INNER JOIN EmployeeProject AS ep Let’s go through some scenarios to solve this problem. Then we'll join the resulting table with Project. First, we need to join tables Employee and EmployeeProject. As you can see, we have to join three tables in order to solve this problem. We can try to solve this problem by using joins. Our main goal is to retrieve all the employee details from table Employee whether they are mapped with EmployeeProject or not. Things to consider: not all the employees from table Employee mapped with table EmployeeProject and not all the projects in table Project mapped with table EmployeeProject. Figure 2: Employee table Figure 3: EmployeeProject table Figure 4: Project table The problem is to get all the employee details and their corresponding projects. The below image is the relational database design: Figure 1: Relational Database Design for the problem ![]() Let’s say we have three tables, namely Employee, Project, and EmployeeProject. The Problem: How to Get Employee Details and Projects I’m running on the default instance of SQL server. If you’re familiar with other relational database management systems such as MySQL or PostgreSQL, then picking up Microsoft SQL Server should be pretty easy. Microsoft SQL Server is a Relational Database Management System that revolutionized how businesses handle data. If you don’t know about Microsoft SQL Server, I’ll briefly explain to you what it is□. In this article, we’ll look at how to use join on more than two tables and aggregate the result using the function STRING_AGG() in Microsoft SQL Server.
0 Comments
Leave a Reply. |