14

I am trying to use CONCAT with SQL to concatenate 3 fields, and get the following error:

Incorrect parameters in the call to native function 'CONCAT'

The query is as follows

SELECT CONCAT(guests.lastname,', ',guests.firstname', ',guests.passport) AS display 
  FROM guests 
 WHERE guests.uuid = '1'

How do you concatenate more than 2 fields in SQL?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502

3 Answers3

31

You must put commas between all the arguments.

Change:

 SELECT CONCAT(guests.lastname,', ',guests.firstname', ',guests.passport)

to:

 SELECT CONCAT(guests.lastname,', ',guests.firstname,', ',guests.passport) 
                                                    ^
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • I've found that Doctrine only accepts two arguments for its CONCAT function. http://www.doctrine-project.org/jira/browse/DDC-670 Not a simple syntax error in my case. Work around being expressing it like: `CONCAT(a, CONCAT(b, CONCAT(c, d)))` – ficuscr Aug 18 '14 at 17:18
3
SELECT CONCAT(guests.lastname,', ',guests.firstname', ',guests.passport) AS display 
FROM guests 
WHERE guests.uuid = '1'

Kindly try the below one,

SELECT guests.lastname||','||guests.firstname||','|| guests.passport AS display 
  FROM guests 
 WHERE guests.uuid = '1'
Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41
Praveen Kumar C
  • 409
  • 4
  • 6
2
SELECT CONCAT(guests.lastname,concat(', ',concat(guests.firstname,concat(', ',guests.passport)))); 
rene
  • 41,474
  • 78
  • 114
  • 152