Why does not this sql query work for me?

0

The first_advisory column is of type DATE, I put an image of the records entered so far:

Making this query:

SELECT primer_aviso FROM tabla_principal WHERE 'primer_aviso' < '2017-12-01'

Is not it supposed that only records that are dated before December 1, 2017 should appear? Because it throws me 0 records. And the following query:

SELECT primer_aviso FROM tabla_principal WHERE 'primer_aviso' >= '2017-12-01' 

Should not you show the records from December 1, 2017 onwards? Because I see all the records in the table. These are the results:

I do not understand why.

    
asked by Oscar Díaz 18.12.2017 в 18:30
source

1 answer

3

By putting the name of the column in quotes, what you are asking is:

The string primer_aviso is < '2017-12-01' or if the string primer_aviso is >= '2017-12-01'

To make SELECT of the column, you must remove the single quotes. If at most you want to use quotation marks, they should be these '', they are not '...', they do not do the same function, as you can understand.

Try this way:

SELECT primer_aviso FROM tabla_principal WHERE primer_aviso < '2017-12-01'

SELECT primer_aviso FROM tabla_principal WHERE primer_aviso >= '2017-12-01'

Or so:

Note that here I put everything (names of tables and columns) with the quotes '' ... question of uniformity . It will usually work both ways.

SELECT 'primer_aviso' FROM 'tabla_principal' WHERE 'primer_aviso' < '2017-12-01'

SELECT 'primer_aviso' FROM 'tabla_principal' WHERE 'primer_aviso' >= '2017-12-01'
    
answered by 18.12.2017 / 18:39
source