MySQL FIND_IN_SET()无法使用JOIN

时间:2014-07-29 13:43:43

标签: mysql

我有这张桌子:

... | products | ...
... | 1, 5, 5  | ...
... | 3, 1, 6  | ...

这个查询:

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;

我需要获取这些行,但它没有给我任何结果,我只使用表orders尝试了查询,并且它有效。那么为什么它不适用于JOIN

1 个答案:

答案 0 :(得分:-1)

尝试此查询:

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;

我已将user_id更改为加入两个表的行中的id