Help please compile MySQL expression to select a car model.

The database has fields: mdoel_id , start , end . Where start and end are the start and end dates of production.

If the user enters a year (one number, for example, 1998), then you need to select all the records between start and end .

  • What type do the start and end fields have? - cheops
  • @cheops int - number - Pavel

1 answer 1

You can do the following:

 SELECT * FROM tbl WHERE 1998 BETWEEN start AND `end` 

This condition is equivalent to

 SELECT * FROM tbl WHERE 1998 >= start AND 1998 <= `end` 

If you do not need to include the boundaries of the year ( start and end ), it is enough to replace the operators> = and <= by> and <.