Help please, there is a table with two columns id and number , please tell me how to make a request for example on the number 50 which is id=60 , id=22 and id=3 , in reverse order .. How to correctly make a query for difference of rows or id of the last number id=60 and the last but one id=22

  • What does the difference in strings mean? - Alexey Shimansky

2 answers 2

If I understand correctly, you need something like this:

 SELCT ((SELECT id FROM table WHERE number = 50 ORDER BY id DESC LIMIT 1 ) - (SELECT id FROM table WHERE number = 50 ORDER BY id DESC LIMIT 1,1 )) as result 
  • is amazing. I did not understand the question, respectively, I do not understand what you all answer about. Now it remains only to accept one of the answers as correct. - splash58
  • Thank you, I thought how much I was sitting, and I completely forgot about LIMIT 1.1))) you correctly understood the need, the previous value is displayed)) but how to output the result via php? - Constantine
  • all) figured out)) thanks a lot) - Constantine
  • @ splash58 I didn’t understand either) decided to guess))) - Alexey Shimansky
  • one
    Congratulations on winning the "battle of psychics" =) - alias

Query the number 50 with the reverse sequence id: SELECT id, number FROM my_table WHERE number = '50 'ORDER BY id DESC

Request for maximum number ID: SELECT id FROM my_table ORDER BY number DESC LIMIT 1