user1253538
user1253538

Reputation:

How to concatenate more than 2 fields with SQL?

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?

Upvotes: 16

Views: 75406

Answers (3)

Praveen Kumar C
Praveen Kumar C

Reputation: 449

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'

Upvotes: 4

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

Upvotes: 3

Mark Byers
Mark Byers

Reputation: 839254

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) 
                                                    ^

Upvotes: 31

Related Questions