MySQL 如何使用 SQL 连接 2 个以上的字段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3182555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:29:19  来源:igfitidea点击:

How to concatenate more than 2 fields with SQL?

sqlmysql

提问by Mark Byers

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

我正在尝试使用 CONCAT 和 SQL 来连接 3 个字段,并收到以下错误:

Incorrect parameters in the call to native function 'CONCAT'

调用本机函数“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?

如何在 SQL 中连接 2 个以上的字段?

回答by Mark Byers

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

回答by Praveen Kumar C

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'

回答by Hope to learn something here

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