-3

Trying to pull the last 50 entries from my DB and then run another select on that query. Essentially I want to see if your name is in the last 50 entries of the DB.

I don't think this needs a join but I'm not really too experienced with anything more then basic sql queries.

This is what I have

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

I've also tried using AND in a query something like this

SELECT * from r2 order by idp desc limit 50 and where name = '$name'
Ryan Litwiller
  • 497
  • 5
  • 24
  • 1
    Possible duplicate of [Alternative to using LIMIT keyword in a SubQuery in MYSQL](http://stackoverflow.com/questions/12810346/alternative-to-using-limit-keyword-in-a-subquery-in-mysql) – Liam Sorsby Feb 18 '16 at 17:55
  • also @LiamSorsby if your going to flag this as a duplicate you should flag it according to this post http://stackoverflow.com/questions/12125904/select-last-n-rows-from-mysql – Ryan Litwiller Feb 18 '16 at 18:10
  • Thank you, I will. However, please don't take things to heart. You are asking for help. If your rude to people you won't get anywhere on this site. – Liam Sorsby Feb 18 '16 at 18:12
  • No problem. So you know I didn't downvote. Just marked it as duplicate. From my standpoint reading the question it looked like the answer would have helped. Hence the duplicate flag. It doesn't matter how little knowledge you come to SO with. As long as the explaination of the problem is complete along with what you've tried and resources you've looked at. The problem being that most questions have already been asked so they are marked as duplicate not because they are poor or people are being horrible but because it creates duplicate content on SO. – Liam Sorsby Feb 18 '16 at 18:35

1 Answers1

0

This solution is what I'm looking for.

mysqli_query($test_db, "SELECT * from (select * from r2 order by idp desc limit 50) 
sub where name = '$name'");
Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51
Ryan Litwiller
  • 497
  • 5
  • 24