Also, depending on the use case, if you want to compare entries (or more than just one column), it's easier to use the toAscii passes in IdM.
Make sure that your SQL returns MSKEYs and by seleting the "use identity store" you can dump all the attributes the entries have to the CSV with column headings etc much easier than you would be able to do in the query tool.
regards, Tero