add option for table name, changed SQL query