FWIW, you could have tried my query in some standalone query tool (e.g., phpmyadmin or whatever it is called) without using your own PHP code. That would have shown you what the query is doing. And whether or not I had it right.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.