Tell me how to organize a search. It is necessary to display the following, or previous 10 lines. For example: the last result of the line ended with id 12, and the following lines with id 27,28,29 .. That is, you need to memorize the last result, knowing which direction the search is going on, forward or backward. I would be very grateful if you help.

  • What does not suit LIMIT 0,10 ? For MySql it is an analogue of TOP 10 from MS SQL. - AK ♦

1 answer 1

What does not suit LIMIT 0,10 ? For MySql it is an analogue of TOP 10 from MS SQL.

 SELECT `ID`, `TIMESTAMP_X`, `LOGIN`, `PASSWORD`, `CHECKWORD`, `ACTIVE`, `NAME` FROM `b_user` WHERE 1 = 1 AND id > 5 LIMIT 0, 2; 

enter image description here

You also ask not only the ten "next" lines, but also the "ten presenters." Here you just need to change the direction using ORDER BY , since negative values ​​in LIMIT cannot be used.

 SELECT `ID`, `TIMESTAMP_X`, `LOGIN`, `PASSWORD`, `CHECKWORD`, `ACTIVE`, `NAME` FROM `b_user` WHERE 1 = 1 AND id < 7 ORDER BY `ID` DESC LIMIT 0, 2; 

enter image description here

  • one
    ORDER BY by the way, you should always specify - without it, SQL does not guarantee the order of rows. the fact that strings are sometimes issued by ID is a coincidence - PashaPash ♦
  • @PashaPash by the way, yes, a good reminder. If it is the order that is important for the topstarter, then you need to specify by which columns to sort. - AK ♦
  • Thank you very much! I'm screw up =)) - Igor Aga