我的工作正常:
$sql = $mysqli->query("SELECT posts.*, members.username, categories.category_name
FROM posts
LEFT JOIN members
ON posts.post.by = members.id
LEFT JOIN categories
ON posts.post_category = categories.category_id
ORDER BY posts.post_date DESC
LIMIT $start, $limit
");
但我想要这个WHERE条件:
WHERE posts.post_by = 1
我无法找到正确的方法,我已经尝试将它放在最后,在LIMIT之前,在FROM帖子之后,但结果是空的。
答案 0 :(得分:2)
where
子句位于from
:
SELECT posts.*, members.username, categories.category_name
FROM posts
LEFT JOIN members
ON posts.post.by = members.id
LEFT JOIN categories
ON posts.post_category = categories.category_id
WHERE posts.post_by = 1
ORDER BY posts.post_date DESC
LIMIT $start, $limit;
join
是from
子句的一部分,这就是我将查询缩进为:
SELECT posts.*, members.username, categories.category_name
FROM posts LEFT JOIN
members
ON posts.post.by = members.id LEFT JOIN
categories
ON posts.post_category = categories.category_id
WHERE posts.post_by = 1
ORDER BY posts.post_date DESC
LIMIT $start, $limit;