Johnny Robertson
Johnny Robertson

Reputation: 147

How do I join two tables in SQL to grab the names from one table and show them in a query?

I have two tables like this:

Employee Table:

EmployeeID firstName lastName
1 Johnny Depp
2 Rebecca Smith
3 Rodger Doe

Sales Table:

EmployeeID Sales
1 100.20
2 200.19
3 355.23

And I'd like to join the tables to do something like this:

EmployeeID fullName Sales
1 Johnny Depp 100.20
2 Rebecca Smith 200.19
3 Rodger Doe 355.23

How would I do that? Here's what I tried so far:

SELECT employee.firstName + employee.lastName AS fullName, employeeID, sales
FROM employee i 
INNER JOIN Sales s ON s.customerID = i.CustomerID

I'm getting a syntax error at my "+" symbol.

What's my problem?

Upvotes: 0

Views: 649

Answers (1)

eshirvana
eshirvana

Reputation: 24568

as @Gordon said ,use CONCAT():

SELECT CONCAT(employee.firstName, ' ', employee.lastName) AS fullName
       , employeeID
       , sales
FROM employee i 
INNER JOIN Sales s 
   ON s.customerID = i.CustomerID 

Upvotes: 2

Related Questions