mysql 查询没有返回想要的结果

标签 mysql sql

我有三个表,我试图从中提取结果,但空手而归。这是我的查询:

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,则无法执行此查询

GROUP BY

关于mysql 查询没有返回想要的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827838/

相关文章:

sql - 我们可以向 SQL Server 数据库/表添加注释或自述文件吗?

SQL 查询 : Group by multiple columns in different tables

mysql - 多个子查询,一个返回多于1行

MySQL:从日期时间字段获取 "busiest"或 "most popular"小时?

mysql - 连接同一列中具有不同条件的 2 个值

php - 如何使用更新语句更新数据库值?

mysql - SQL Order By查询问题

php - 连接后计算表中的行数

java - Camel jdbc : How can I reset datasource if mysql connection gets closed

php - Laravel - 从一个表中获取另一个表中不存在的记录并附加 where 子句