issue 1165 make SQL/CSV mode work when 2 tables are used + test