Csharp
Csharp

Reputation: 2982

SQL Query joins

I have a table called tblIssueTicket tblIssueTicket contains the fields: TicketID, TicketRequesterID, ApprovalManagerID, RequestDate, ApprovalDate, TicketStatus

There is another table called tblEmployeeProfile. tblEmployeeProfile contains fields EmployeeID, EmployeeFirstName, EmployeeLastName

I need to display the following records:

TicketID, TicketRequesterFullName, ApprovalManagerFullName, RequestDate, ApprovalDate, TicketStatus

I am having problems figuring out the query to return the fullname of the TicketRequester & fullname of ApprovalManager fields.

My query so far looks like this:

Select it.TicketID,
    ep.Firstname + ' ' + ep.EmployeeLastName AS TicketRequestorFullName,
    it.RequestDate, it.ApprovalDate, it.TicketStatus
FROM    tblIssueTicket it, tblEmployeeProfile ep
WHERE   ep.EmployeeID = it.TicketRequesterID

Any advice would greatly appreciated.

Thanks

CM

Upvotes: 0

Views: 177

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300827

SELECT
  it.TicketID,    
  ep.Firstname + ' ' + ep.EmployeeLastName AS TicketRequestorFullName,    
  mp.Firstname + ' ' + mp.EmployeeLastName AS ApprovalManagerFullName,    
  it.RequestDate, 
  it.ApprovalDate, 
  it.TicketStatus
FROM    
  tblIssueTicket it
  INNER JOIN  tblEmployeeProfile ep ON ep.EmployeeID = it.TicketRequesterID
  INNER JOIN  tblEmployeeProfile mp ON mp.EmployeeID = it.ApprovalManagerID

Upvotes: 5

Related Questions