![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
SELECT * FROM EMPLOYEE e INNER JOIN EMPLOYEE_BENEFITS eb ON (e.employee_id = eb.employee_entity OR e.empsid_id = eb.employee_entity) INNER JOIN EMPLOYEE_TRACK et ON eb.employee_benefits_id = et.employee_track_entity The above SQL I wrote is this: the second inner join uses a OR to join either of the columns in the first table EMPLOYEE. There is performance degradation with this SQL. With huge data It takes about 30 seconds to execute. I know this is not the perfect way to do it, can anyone of the SQL Gurus please enlighten me to a faster approach? |
|
If I dont use the OR I can try left join on the same table EMPLOYEE_BENEFITS twice by changing the join types, but If I did this what table alias can I use to join to the 3rd table? SELECT * FROM EMPLOYEE e LEFT JOIN EMPLOYEE_BENEFITS eb1 ON e.employee_id = eb.employee_entity LEFT JOIN EMPLOYEE_BENEFITS eb2 ON e.empsid_id = eb.employee_entity INNER JOIN EMPLOYEE_TRACK et ON [???].employee_benefits_id = et.employee_track_entity |
#3
| |||
| |||
|
#4
| ||||||
| ||||||
|
|
Can someone help me with this SQL? |
|
1) EMPLOYEE table has columns 'employee_id' and 'emp_sid' and other columns |
|
2) EMPLOYEE_BENEFITS table has a column called employee_entity, this column can be joined to either 'employee_id' OR 'emp_sid' but not both in the EMPLOYEE table. |
|
3) EMPLOYEE_TRACK table has column called employee_track_entity, this column can be joined to the employee_benefits_id (PK) of the EMPLOYEE_BENEFITS table. |
|
The above SQL I wrote is this: the second inner join uses a OR to join either of the columns in the first table EMPLOYEE. There is performance degradation with this SQL. With huge data It takes about 30 seconds to execute. |
|
I know this is not the perfect way to do it, can anyone of the SQL Gurus please enlighten me to a faster approach? |
![]() |
| Thread Tools | |
| Display Modes | |
| |