Question : Recursive Query ?

Ok, this may be a bit difficult to explain.

what i'm tring to do is get a query to return results a User table that has 1 to many relationships with two tables. For example:

Let's say table one is the User table and has the ID colmen that ties to the two other tables, and a Name Column.

Table two is a requesting table: it is joined to the user table by wher the request.requestorId = user.ID
Table three is an approver table: it is joined to the user table  where the approver.approverId = user.ID

They use the same iD in the user table. what i need, in the result set is:

UserId, RequestorName, ApproverName

They both join to the user table, but it's difficult for me to show both names, i can get either requestor, or approver, but not both....

I have two joins

requestroId=userid
approverId=userid (same table as above)

Any good way to resolve this ?

Answer : Recursive Query ?

sorry neglected the field names

also if you want to show the records even if there is nothing for them to join to you can change the joins to left joins
1:
2:
3:
4:
select u.id as userid, r.name as requestorname, a.name as approvername
from users u
join requesting r on r.requestorid = u.id
join approver a on a.approverid = u.id
Random Solutions  
 
programming4us programming4us