我已加入两个表时如何使用DESC限制3

时间:2019-07-08 23:13:01

标签: php mysql

我有两个表的joinend,它像它应该的那样工作,但是现在我想使用DESC限制,但是我不知道我应该把它放在哪里

$query = 'SELECT * FROM posts INNER JOIN category ON posts.catid=category.id;';
$select_all_posts_query = mysqli_query($link, $query);

2 个答案:

答案 0 :(得分:0)

如果您只想限制结果,则可以在查询中添加LIMIT 3

$query = 'SELECT * FROM posts INNER JOIN category ON posts.catid=category.id; LIMIT 3';
$select_all_posts_query = mysqli_query($link, $query);

或者,如果您还尝试按降序排列结果,则还需要向查询中添加ORDER BY

$query = 'SELECT * FROM posts INNER JOIN category ON posts.catid=category.id; ORDER BY posts.id DESC LIMIT 3';
$select_all_posts_query = mysqli_query($link, $query);

答案 1 :(得分:0)

$query = 'SELECT * FROM posts INNER JOIN category ON posts.catid=category.id ORDER BY posts.catid=category.id DESC LIMIT 3 ';
$select_all_posts_query = mysqli_query($link, $query);