在MySQL中将字符串与字段值连接
我需要在MySQL查询中将一个字符串与一个字段值连接起来,以便左联接两个表.
I have the need to concatenate a string with a field value in a MySQL query in order to LEFT JOIN two tables.
表1中有一列名为"category_id"的数字,例如61、78、94等.
Table one has a column called "category_id" with numeric values, such as 61, 78, 94 and such.
表2中有一列查询",它表示请求路由机制,其值包括"product_id = 68","category_id = 74","manufacturer_id = 99"等等.
Table two has a column called "query" which refers to a request route mechanism, and it has values such as "product_id=68", "category_id=74", "manufacturer_id=99" and so on.
因此,在我的查询中,只要从设置字符串派生的串联字符串和"category_id"列的值与查询字段匹配,我就需要连接表.
So in my query I require to join the tables when ever a concatenated string derived from a set string and the value of the "category_id" column matches the query field.
我的SQL语句当前为:
My SQL statement is currently:
SELECT * FROM tableOne
LEFT JOIN tableTwo
ON tableTwo.query = 'category_id=' + tableOne.category_id
我尝试使用||运算符而不是+运算符,但仍然没有运气.是否有可能在MySQL中执行此操作,或者我已经在这里开枪了?
I have tried using the || operator instead of the + operator, but still no luck. Is it possible to do this in MySQL, or have I jumped the gun here?