Compare 2 rows of the same table

Asked

Viewed 1,563 times

0

I need to make a MYSQL query. I have a table in which I have column "data_emissao" and "data_expiration". I need to find all the lines where they have the same due date, but different dates of issue. How can I compare rows like this from the same table?
EX:

Produto | data_emissao | data_venc
   A    |  02/01/2016  | 02/01/2020
   B    |  04/07/2013  | 02/01/2020

The SQL query should return the due date 02/01/2020

  • Junction taking into consideration that the due date is equal and the date of issuance of the product to the left less than the right?

  • The date of issuance may be both higher and lower, that is, it only has the condition of being different.

  • @Christian if the answer helped, please mark the answer as useful and correct.

1 answer

1


Below is an example of how it should be done:

SELECT 
    T1.PRODUTO, T1.DATA_EMISSAO, T1.DATA_VENCIMENTO
FROM 
    TABELA T1
INNER JOIN 
    TABELA T2 ON T2.DATA_VENCIMENTO = T1.DATA_VENCIMENTO
WHERE 
    T1.DATA_EMISSAO <> T2.DATA_EMISSAO
  • In the case I understood only the due dates matter. The rest could be ignored

Browser other questions tagged

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