Compare 2 rows from the same table

0

I need to make a MYSQL query. I have a table in which I have column "data_emission" and "date_wind". I need to find all the lines in which they have the same expiration 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

    
asked by anonymous 28.02.2018 / 20:28

1 answer

1

Here is an example of how to do it:

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
    
28.02.2018 / 20:47