jeudi 7 juillet 2016

Populate data from joined table in SQL

I have a table which has following structure

Employee Relation Table:

| FromEmployeeRelation | ToEmployeeRelation | CreatedAt | UpdatedAt |
+----------------------+--------------------+-----------+-----------+
| 2                    | 3                  | Date      | Date      |

Relation Table

| Id | EmployeeId | CreatedAt | UpdatedAt |
+----+------------+-----------+-----------+
|2   | 5          | Date      | Date      |
|3   | 7          | Date      | Date      |

Id from Relation table in Foreign key for both FromEmployeeRelation and ToEmployeeRelation in Employee Relation Table

I am trying to get info from Employee Relation Table with actual employee id in the results

Result

| FromEmployeeId | ToEmployeeId | FromEmployeeRelation | ToEmployeeRelation  
+----------------+--------------+----------------------+-------------------
| 5              | 7            | 2                    | 3  

From join I can get EmployeeId from one relation, but I am not sure how to get employee id for both the relations.

How can this be done? Thanks

Aucun commentaire:

Enregistrer un commentaire