Mysql 如何在SELECT查询中连接两个字符串?

Mysql 如何在SELECT查询中连接两个字符串?,mysql,string-concatenation,Mysql,String Concatenation,我得到了以下问题: SELECT IF(e.business_id IS NOT NULL, b.name, SUBSTRING_INDEX(p.names, ' ', 1)) as name, f.code, f.total, f.date FROM business AS b INNER JOIN entity AS e ON b.id = e.business_id INNER JOIN persons AS p ON e.person_id = p.id INNE

我得到了以下问题:

SELECT
  IF(e.business_id IS NOT NULL, b.name, SUBSTRING_INDEX(p.names, ' ', 1)) as name,
  f.code,
  f.total,
  f.date
FROM business AS b INNER JOIN entity AS e ON b.id = e.business_id
  INNER JOIN persons AS p ON e.person_id = p.id
  INNER JOIN transactions AS t ON e.id = t.entity_id
  INNER JOIN bills AS bi ON t.id = bi.transaction_id
  WHERE e.type = 2 AND t.type_id = 1;
如果
entity
表中的
business\u id
为空,则我需要从人员中加入一个姓名和一个姓氏。我在一个名为
names
的字段中存储人员姓名,例如Steven Paul,在一个名为
names
的字段中存储人员姓氏,例如Jobs


到目前为止,我用
SUBSTRING\u INDEX(p.names,,,1)
获得了名称,但是如何将该字符串连接到
SUBSTRING\u INDEX(p.names,,,,1)
中,并用空格分隔?

也许您真正想要的是

返回列表中的第一个非NULL值,如果没有,则返回NULL 非空值


您是否阅读过有关?要连接两个字符串,您应该使用CONCAT或CONTACT_WS,例如从表中选择CONCAT(tbl.firstname,“,tbl.lastname)作为全名;你好,我在复习我以前的一些答案。你把这件事解决了吗?
SELECT
  COALESCE(e.business_id, CONCAT(SUBSTRING_INDEX(p.names, ' ', 1),' ', SUBSTRING_INDEX(p.surnames, ' ', 1)) ...