Last records based on a filter

0

Next, I need to bring in a query the last records that have not changed in the last 3 days from a specific ID , eg (id_chamado_status = '1') .

    
asked by anonymous 14.11.2017 / 17:40

2 answers

0

As far as I know, you can not get "unchanged" records from the bank. If someone changes the records it will simply be changed in the database (just the person has permission).

If you want to fetch the date "3" days ago, the moment you enter your data you should also save the insertion date, for example, in a column of type DATE with a specific name, here I am going to use the name DT_REGISTRO and fetch the data there:

SELECT * FROM <nome_sua_tabela> where DT_REGISTRO > 3
    
14.11.2017 / 17:44
0

To search for the first or last record, you must first sort the query. Filter the result and then "get" the return.

Obs. To search for the latest records, sort the query in descending order.

Example:

SELECT CAMPO1, CAMPO2
FROM   TABELA
WHERE  FILTRO
ORDER BY CAMPO_DE_ORDENACAO DESC
LIMIT NUMERO_DE_REGISTROS

Search source: My SQL documentation - Limit

    
14.11.2017 / 17:57