Glad I could help. Here's a tip I always use myself.
Get yourself a copy of a desktop database that has a good Query-by-Example such as Access. Copy your MySQL database tables and structure to it. Access has a drag and drop query designer that you can use to create and test your queries. Once you have the correct result set coming out, you can go to the SQL View and copy and paste the SQL statement into your script. A desktop database will also return more info when you have an error in your query.
Even though it will need some editing, I find it a lot quicker to edit than type the whole query from scratch, especially when there are a lot of fields included by name. I do this all the time.
You should generate a set of test data so that you know what the result of your query should be before you test it. In your example, you should know that the var1 list should have 3 entries, and know which those entries are. You could then test by editing 1 of the var2s and see if the var1 disappears from the list, etc.
Every database engine has it's own flavour or dialect of SQL, so you will have to watch out for different syntax: eg Access uses SELECT INTO instead of MAKE TABLE; it inserts extra () and can rename fields and expressions in inconvenient ways. The trade-off is that it has a good Help system for info on SQL statements and operators, and even sometimes lists when Jet SQL does not conform to the SQL RFC.