I bring you a question I have about a query that brings me headlong. I have a single table that is inherited from a previous project.
In the table among many other data, I have a DNI, a certificate date (FCert) and a renewal date (FRev). In this table a record is stored every time someone goes and a certificate is made. So it has many people repeated and does not have a unique ID.
I am trying to make a query to return to me the people who got a certificate in 2006 (YEAR (FCert) = 2006) and returned to become one in 2016 (YEAR (FRev) = 2016). That is, there must be two DNI records in the table, one with each data.
I have attached the query as I do now, but it returns rare and duplicate values.
SELECT a.'DNI', a.'tabla', a.'FRev', a.'FCert', a.'FNac' FROM 'tabla' AS a JOIN tabla AS b ON (a.DNI = b.DNI)
WHERE YEAR(a.'FRev') = 2016 AND YEAR(b.'FCert') = 2016
ORDER BY a.'DNI' DESC
If you can throw me a cable, I'm stuck there.