I have the following query
SELECT * FROM usuarios
WHERE NOT EXISTS (SELECT * FROM pagos
WHERE pagos.id = usuarios.id AND mes =< '$mes' AND ano =< '$year' )
I am trying to show or select the users who have not made payments in a range no longer than a month, I can get it to show me if the year is different but I cannot show it if the month is different, what could I be doing wrong.
You have complicated yourself a lot. Wouldn't it be easier to choose directly from payments the records of a month in a year?
Example: http://sqlfiddle.com/#!9/3b494/4