我有三个表,我试图从中提取结果,但空手而归。这是我的查询:
SELECT f . *, o . *, u.username, COUNT (o.order_id) as cnt
FROM products f, orders o, users u
WHERE f.product_id=o.product_id
AND f.user_id = u.id
AND (f.title LIKE '%hlt%' OR f.description LIKE '%hlt%' OR u.username LIKE '%hlt%')
LIMIT 5
这没有返回任何结果,尽管肯定有满足此条件的记录(尽管显然不是我写的那样)。
最佳答案
您使用了 COUNT (o.order_id)
而不使用 group BY
。这导致了问题。如果不使用 GROUP BY,则无法执行此查询
关于mysql 查询没有返回想要的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827838/