How to fix Error 4163 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 4163 — “GROUP BY Clause Required in PROB_MATCH Query” (SQL Server 2025)

Why This Error Happens

This error occurs because SQL Server 2025’s PROB_MATCH function — used for probabilistic fuzzy matching operations — is implemented as an aggregate function internally, requiring an explicit GROUP BY clause to define the scope of comparison for each match set. When a query calls PROB_MATCH alongside other selected columns without grouping those columns, the query optimizer cannot determine how to partition the rows for scoring, triggering Error 4163. This is typically a query construction issue rather than a server configuration or permissions problem, though outdated compatibility levels or corrupted statistics on the matching columns can sometimes mask the root cause.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Open SQL Server Management Studio (SSMS) 21 or Azure Data Studio connected to your Windows Server 2025 instance.
  • Locate the exact query referenced in the SQL Server Error Log (C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) or Activity Monitor.
  • Confirm the query includes a PROB_MATCH() function call mixed with non-aggregated columns in the SELECT list.

Step 2: Add the Required GROUP BY Clause

  • Edit the query so every non-aggregated column in the SELECT list is included in a GROUP BY clause.
  • Example corrected syntax:
  SELECT CustomerName, AddressLine1,
         PROB_MATCH(CustomerName, AddressLine1) OVER (PARTITION BY RegionID) AS MatchScore
  FROM dbo.CustomerStaging
  GROUP BY CustomerName, AddressLine1, RegionID;
  • If using PROB_MATCH in a windowed context, ensure PARTITION BY columns align with your intended match groups instead of (or alongside) GROUP BY.

Step 3: Validate Database Compatibility Level

  • Right-click the database in SSMS → Properties → Options → confirm Compatibility Level is set to 170 (SQL Server 2025).
  • Alternatively, run:
  ALTER DATABASE [YourDatabase] SET COMPATIBILITY_LEVEL = 170;
  • Older compatibility levels can cause PROB_MATCH to behave unpredictably or throw inconsistent grouping errors.

Step 4: Rebuild Statistics on Matching Columns

  • Run UPDATE STATISTICS dbo.CustomerStaging WITH FULLSCAN; on the table(s) referenced in the PROB_MATCH call.
  • This ensures the query optimizer has accurate cardinality estimates when evaluating the grouped probabilistic match sets.

Alternative or Verification Steps

  • Re-execute the corrected query and confirm it returns results without Error 4163; check sys.dm_exec_query_stats to verify the execution plan no longer flags a missing aggregation context.
  • If the error persists, isolate PROB_MATCH into a derived table or CTE with its own explicit GROUP BY, then join it back to the main query to avoid column-scope conflicts.