Sorry, I'm at work.
Start by adding an rbe node downstream of your query output so that you can see how it works. Then add a change node after that that sets a flow variable - perhaps to false. Then add another flow that listens to the MQTT topic and uses a change node to set the flow variable to true. Finally, work out where to put the switch node that checks the variable and only allows the message to pass if it is false.
Along the way, think about ways to simplify the logic because it strikes me that you've invented an approach in your head that could actually be greatly simplified.