>Hi Sergey its mysql
>
>but between posting and your reply I realised what I had done wrong.
>
>t.pop and s2.pop aren't proper dates they are YYYYMM and that was not giving an error from datediff but was giving the wrong number
>
>Thanks
>
You need to put the dates condition outside (e.g in the outer select statement) although it may help to put condition in both statements.
Keep in mind, that this SQL is not going to perform well on big volumes of data.
If it's not broken, fix it until it is.
My Blog