0

I have following mysql table: Table Name:PaymentHitory

journeyID | passengerID  | driverID 
---------------------------  
1         |    1         |3  
2         |    2         |4 

Table Name:UserInformation

userID | firstName
------------------
1      |    ABC         
2      |    XYZ        
3      |    PQR         
4      |    MSN

I want result like

 journeyID | passengerName  | driverName 
------------------------------------------  
    1      |    ABC         |PQR  
    2      |    XYZ         |MSN 
2
  • driverName is not in all the two tables,then how will you retrieve that Commented Jun 20, 2014 at 9:47
  • Where is the passengerName and driverName? Commented Jun 20, 2014 at 9:47

1 Answer 1

4

It's a simple join on the tables:

select journeyID, pax.firstName as passengerName, dri.firstName as driverName 
    from PaymentHistory pay 
    join UserInformation pax on pay.passengerID = pax.userID 
    join UserInformation dri on pay.passengerID = dri.userID
Sign up to request clarification or add additional context in comments.

1 Comment

@GordonLinoff Sure !! You will get credit from question owner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.