0

I have a simple select statement in MySQL written below. It keeps giving me a syntax error for the first + sign in the concatenation and I cannot figure out why. I also tried using the concat function and an error occurs as well.

select 1.VendorID, 1.VendorName, 1.VendorContactFName + " " + 1.VendorContactLName as Name
from Vendors as 1 JOIN
     Vendors as 2
     on 1.VendorID <> 2.VendorID and
        1.VendorContactFName = 2.VendorContactFName
order by Name;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Santi
  • 1
  • 1

2 Answers2

2

First, don't use numbers as table aliases. Second, to concatenate strings, use concat(). Third, single quotes are the normal delimiter for strings.

So:

select v1.VendorID, v1.VendorName,
       concat(v1.VendorContactFName, ' ', v1.VendorContactLName) as Name
from Vendors as v1 JOIN
     Vendors as v2
     on v1.VendorID <> v2.VendorID and
        v1.VendorContactFName = v2.VendorContactFName
order by Name; 
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Try it with the concat function instead:

CONCAT(1.VendorContactFName, ' ', 1.VendorContactLName) as Name

It might be what you need. But I think it will return null if any of the parameters are null.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131