added missing select query conditions