Comparison between mysql fields

Asked

Viewed 88 times

1

I have a Mysql table where I store the years I took from a register, but I am creating a search where the user selects from one date to another. In Mysql I did so:

SELECT * FROM tabela WHERE AnoEmpresa BETWEEN 1970 and 2014;

Only that it does not return anything, even having data within these dates.

  • What is the type of column AnoEmpresa?

  • CHAR...I didn’t even touch it. If I convert to YEAR, I lose the registered information?

  • I converted from CHAR to YEAR and it worked... thank you!

1 answer

2


Your query seems correct.

The only thing I can imagine is that you have the spine AnoEmpresa in a non-numeric format. In this case Mysql will be looking for a string. (probably with the size between 1970 and 2014 characters). Try switching to a numeric type or date: TINYINT, YEAR or DATE...

  • 1

    Thank you Sergio......

Browser other questions tagged

You are not signed in. Login or sign up in order to post.