Mysql 将WHERE语句与CONCAT一起使用时未显示的所有记录

Mysql 将WHERE语句与CONCAT一起使用时未显示的所有记录,mysql,join,concatenation,where-clause,Mysql,Join,Concatenation,Where Clause,我有一个植物列表,可以用CONCAT过滤,最初它只是文本,但我把它转换成了ID。它显示了所有的记录,可以在我转换为ID之前进行过滤 这涉及4个表。(对于示例数据),字段中不使用“”,它们只是向您显示它是一个单词 植物 idplant example 1 plantname example "001 Forklift" idplanttype1 example 1 idlocation1 example 1 iddepartment1 example 1 植物类型 idpla

我有一个植物列表,可以用CONCAT过滤,最初它只是文本,但我把它转换成了ID。它显示了所有的记录,可以在我转换为ID之前进行过滤

这涉及4个表。(对于示例数据),字段中不使用“”,它们只是向您显示它是一个单词

植物

idplant example 1
plantname example "001 Forklift"
idplanttype1 example 1
idlocation1 example 1
iddepartment1 example 1
植物类型

idplanttype example 1
planttype example "Forklift Truck"
idlocation example 1
location example "Preston"
iddepartment example 1
department example "Waste Disposal"
地点

idplanttype example 1
planttype example "Forklift Truck"
idlocation example 1
location example "Preston"
iddepartment example 1
department example "Waste Disposal"
部门

idplanttype example 1
planttype example "Forklift Truck"
idlocation example 1
location example "Preston"
iddepartment example 1
department example "Waste Disposal"
如果没有WHERE语句,它将显示所有记录,包括NULL。(但过滤器不工作)

但是对于WHERE语句,它只显示完整的记录(所有记录都没有空字段,并且过滤器工作),不显示空的记录

问题似乎是康卡特。(我已经清理了括号,但必须添加1以使id不同)

解决方案 上面的代码是有效的,只是缺少了

WHERE CONCAT_WS
我是新加入的,所以任何帮助都将不胜感激

编辑:使用Linux服务器-Apache版本2.4.46


提前谢谢

您的问题可能是空白

WHERE CONCAT(plantname, planttype, location, department) 
 LIKE '%001 Forklift Forklift Truck Preston Waste Disposal%' 
找不到任何内容,例如,由于混凝土字符串导致
'001叉车废物处理'
,而不是
'001叉车普雷斯顿废物处理'

子字符串之间需要空格,这是使用
CONCAT\u WS
最容易实现的:

SELECT p.idplant, p.plantname, pt.planttype, l.location, d.department
FROM plant p
INNER JOIN planttypes pt ON pt.idplanttype = p.idplanttype1
INNER JOIN locations l ON l.idlocation = p.idlocation1
INNER JOIN departments d ON d.iddepartment = p.iddepartment1
WHERE CONCAT_WS(' ', p.plantname, pt.planttype, l.location, d.department) 
        LIKE '%001 Forklift Forklift Truck Preston Waste Disposal%' 

请详细说明你想要什么样的唱片?从您的问题来看,这并不清楚。请提供每个表中数据的示例。您应该首先删除连接条件周围所有无用的括号,这样可以更轻松地读取查询。请为您正在使用的DBMS产品(Postgres、Oracle等)添加标签。那太好了,谢谢,我不得不稍微处理一下,但你说得对