My MySQL has a time table with min and sec columns in which numbers are stored. The user enters two numbers (for example, min1 and sec1).

Please tell min <= min1 how to create a query in SQL that would select from the time table only the entry with min <= min1 and sec <= sec1 , while this entry has the maximum min that satisfies the condition (and if there are several such entries, then a record with a large sec satisfying the condition.)

Those. speaking Russian, I need to make sure that the maximum time ( min and sec ) that is less than the value entered by the user is selected from the table.

  • There is such a function in sql - MAX w3schools.com/sql/sql_func_max.asp - naym
  • one
    SELECT * FROM table WHERE min <= 'min1' AND sec <= 'sec1' ORDER BY min DESC, sec DESC LIMIT 1 - Indifferent

1 answer 1

The answer from the comment from indifferent

 SELECT * FROM `time` WHERE `min` <= 'min1' AND `sec` <= 'sec1' ORDER BY `min` DESC, `sec` DESC LIMIT 1