The bottom line is this. There is an entry in the table with an integer field "field" and you need to pull out another entry that has the value of this field more than the current record, but less than all other records in this table. I'm stupid for something = \

  • Need to pull out such records for each record of the table or only one? If there is one, then the initial one should at least know the id or the value of the field. Is the "field" field unique, or are repetitions possible? - aachurin

4 answers 4

Is this not the second entry when sorting in ascending order .... ??

  • She agrees by herself - Timenzzo
  • I was stupid =) Today I go to bed at 00:00)) Thank you all for the answers. All plus signs, except for those who tried to solve the problem with the help of subqueries. Guys, no offense, but this is some kind of perversion = \ - Vitaly Kustov
  • In this situation, Modus was the closest, so that its laurels ... - aachurin
  • @aachurin, I do not agree ... According to the condition - "than all the other entries in this table", and not "than other big ones", so his query is not at all true! - timka_s
  • I read the question carefully, really, you're right. But it will make sense only if the field value of the current record is certainly less than the field values ​​of other records in the table. - aachurin

value - the value with which to compare

SELECT * FROM `table` A WHERE `field` > value AND `field` < ALL (SELECT `field` FROM `table` B WHERE A.field != B.field AND B.field != value) 

    SELECT TOP 1 * FROM table WHERE field> @value ORDER BY field ASC

       SELECT t.field, ( SELECT MIN(_t.Field) FROM TableName _t WHERE _t.Field>t.Field ) FROM TableName t