mysql - 如何在多列连接表上进行搜索?

标签 mysql sql

我不断收到错误消息,提示 t.product_id 列未知。 我使用了这段代码:

SELECT
    t.product_id as ID,
    product_category as Category,
    product_name As Product,
    product_price as Price,
    product_decription as Description,
    t.Stats as 'Status',
    tblinventory.quantity
FROM tblproduct as t
INNER JOIN tblinventory
    on t.product_id = tblinventory.product_id
WHERE 
    CONCAT(`t.product_id`,`product_category`,`product_name`,`t.Stats`) LIKE '%"2"%'

我似乎无法让它发挥作用。 tblproduct 具有列product_id、product_category、product_name、product_price、product_description 和 stats

而 tblinventory 具有 Product_id 和数量列

最佳答案

在 MySQL 中,`t.product_id` 指的是具有该名称的列 - “t.product_id”,而不是表 t 中的列 product_id。删除转义字符:

WHERE CONCAT(t.product_id, product_category, product_name, t.Stats) LIKE '%"2"%'

您不需要转义名称,所以不需要。

关于mysql - 如何在多列连接表上进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47117940/

相关文章:

java - jdbc连接-socket连接

php - 如何在不删除mysql中当前值的情况下更新行?

php - 使用 PDO 计算 MySQL 表中的行数

sql - 如何做相当于 "limit distinct"?

c# - 当我将我的网站上传到 smartasp.net 时,出现错误 : SQL Network Interfaces, error: 26

mysql - 如何 LEFT JOIN 表,采用 SUM() 或使用 WHERE 子句返回 0?

mysql - SQL:用假人填充有序字符串序列中的缺失

sql - SQL数据库之间的差异列表

php - 图片文件权限不起作用

php - 使用 PDO 事务的副作用