[英]MySQL FIND_IN_SET() not working with JOIN
I have this table: 我有这张桌子:
... | products | ...
... | 1, 5, 5 | ...
... | 3, 1, 6 | ...
And this query: 而这个查询:
SELECT
orders.id,
orders.user_id,
users.username,
orders.products,
orders.rating,
orders.payment,
orders.comment
FROM
orders JOIN users
ON orders.user_id = users.id
WHERE
FIND_IN_SET(1, REPLACE(orders.products, ' ', '')) > 0;
I need to get these rows but it gives me no result, I've tried the query using only the table orders
, and it works. 我需要获取这些行,但它不会给我任何结果,我仅使用表orders
尝试了查询,并且该方法有效。 So why it does not work with JOIN
? 那么,为什么它对JOIN
不起作用?
Try this query: 试试这个查询:
SELECT
orders.id,
orders.user_id,
users.username,
orders.products,
orders.rating,
orders.payment,
orders.comment
FROM
orders JOIN users
ON orders.id = users.id
WHERE
FIND_IN_SET(1, REPLACE(orders.products, ' ', '')) > 0;
I have changed user_id
to id
in the line that joins the two tables. 我已将连接两个表的行中的user_id
更改为id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.