选择“最后 50”,然后选择该查询的另一个选择 - MYSQL PHP


Select Last 50 then another select of that query - MYSQL PHP

尝试从我的数据库中提取最后 50 个条目,然后对该查询运行另一个选择。从本质上讲,我想看看你的名字是否在数据库的最后 50 个条目中。

我认为这不需要联接,但我对基本的 sql 查询没有太多经验。

这就是我所拥有的

mysqli_query($test_db, "SELECT * from r2 order by idp desc limit 50 
(select * where name = '$name')");

我也尝试过在这样的查询中使用 AND

SELECT * from r2 order by idp desc limit 50 and where name = '$name'

这个解决方案就是我正在寻找的。

mysqli_query($test_db, "SELECT * from (select * from r2 order by idp desc limit 50) 
sub where name = '$name'");