Author |
Topic |
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2008-12-30 : 14:02:55
|
Lets say I have a table Task with column assignedEmployeeId and terminatedByEmployeeIdI need to create a View something likeselect * from Task inner join Employee on Employee.id = Task.assignedEmployeeIdinner join Employee on Employee.id = Task.terminatedByEmployeeIdI was wondering if there isn't another syntax, like in one line ....???I'm pretty noob in sql sorryThanks for the help |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 14:13:21
|
did you mean thisSELECT *FROM(SELECT assignedEmployeeId AS EmpID,otherfields... FROM TaskUNION ALLSELECT terminatedByEmployeeId,... FROM Task)tINNER JOIN Employee eON e.id =t.EmpID |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2008-12-30 : 14:25:55
|
hmm the above seem complicated, let me correct the sqlselect t.*, e1.employeeName, e2.employeeName from Task AS tinner join Employee AS e1 on e1.id = t.assignedEmployeeIdinner join Employee AS e2 on e2.id = t.terminatedByEmployeeIdhope it's clearer ... maybe it's just me, i don't get the union thing |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 15:04:32
|
quote: Originally posted by GoDaddy hmm the above seem complicated, let me correct the sqlselect t.*, e1.employeeName, e2.employeeName from Task AS tinner join Employee AS e1 on e1.id = t.assignedEmployeeIdinner join Employee AS e2 on e2.id = t.terminatedByEmployeeIdhope it's clearer ... maybe it's just me, i don't get the union thing
so how do you want to modify above query? |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2008-12-30 : 15:39:27
|
Im not having a problem per say. Just wondering if there is a more elegant way maybe?A better way? Or this is usually how is done? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2008-12-30 : 16:26:22
|
oh, I just want to select the name of the employee assign to the task and also select the name of the employee that has terminated the task |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2008-12-30 : 17:06:56
|
ok thanks, its the same select as I did, I guess that's the usual way. |
|
|
|