bug 1008: fixed sql-statement
bug 1008: fixed query output from $res to $res1