fixed query for tables