Check out a record in order of priority

Simple trick by which to extract a previous record to another to auto-increment ID value, imagine you want to remove the previous record that has the ID value “10″ is not mentioned in the table is This ID “9″, this may have been erased, then the simple statement:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">SELECT * FROM t WHERE id = 9;</span> SELECT * FROM t WHERE id = 9;</span>

may have no effect, however utilize the following statement:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">SELECT * FROM t WHERE id < 10 ORDER BY id DESC LIMIT 1;</span> SELECT * FROM t WHERE id <10 ORDER BY id DESC LIMIT 1;</span>

This will extract the first record whose ID value lower than that used in the WHERE clause, it may also be, for example “3″, in fact, if at least one has been kept the number of deleted records will not matter.

Likewise, to extract the first record following one considered education to be used should be defined along the lines of the following:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">SELECT * FROM t WHERE id > 10 ORDER BY id ASC LIMIT 1;</span> SELECT * FROM t WHERE id> 10 ORDER BY id ASC LIMIT 1;</span>

This entry was posted in Database and tagged , , . Bookmark the permalink.

Comments are closed.