---
title: "Why WHERE fieldA = fieldB Fails in WQL — Kiweely"
description: "Understand why comparing two fields directly in a WQL WHERE clause throws \"Invalid Where Clause\" and how to compare fields on the same business object."
url: https://kiweely.com/guides/wql-compare-two-fields-where-clause-invalid
---

# Why WHERE fieldA = fieldB Throws “Invalid Where Clause” in WQL

WQL is SQL-like but does not allow field-to-field comparisons such as WHERE totalApprovalLevel = currentApprovalLevel in the WHERE clause. Learn how WQL evaluates WHERE operands, how to use a True/False Calculated Field or post-query filtering, and how to use COUNT() syntax properly.

-   **Checked** against Workday on November 6
-   Applies to **Workday Query Language**
-   3 min read
-   Published November 6
-   By Kiweely

## Why `WHERE fieldA = fieldB` Fails with `Invalid Where Clause`

In standard SQL, you can compare two columns on the same table row directly inside a `WHERE` clause. When developers attempt the same pattern in Workday Query Language (WQL)—for example, counting records on an Extend Model Business Object or Workday data source where `totalApprovalLevel` equals `currentApprovalLevel`—WQL rejects the query with `Invalid Where Clause`:

sql

```
SELECT count() AS recCount
FROM customApprovalRequests
WHERE totalApprovalLevel = currentApprovalLevel
```

WQL throws `Invalid Where Clause` because the WQL parser strictly requires the right-hand side of every comparison operator (`=`, `!=`, `>`, `>=`, `<`, `<=`, `contains`, `in`, etc.) to be a **literal value** (a number, boolean, quoted string, quoted date, or instance Workday ID/reference ID), never another field alias.

According to Workday’s *WQL Reference: WHERE* specification, every conditional expression follows the grammar:

sql

```
WHERE
  field1 = value1
  AND field2 IN (instance1, instance2)
  OR field3 IN (inst_refId = referenceID)
```

When you write `WHERE totalApprovalLevel = currentApprovalLevel`, WQL attempts to parse `currentApprovalLevel` as an unquoted literal value for `totalApprovalLevel`. Because `totalApprovalLevel` is a numeric or text field rather than an unquoted boolean or valid literal, the parser halts and returns `Invalid Where Clause`.

## How to Compare Two Fields on the Same Business Object

Because WQL cannot evaluate `fieldA = fieldB` (or `fieldA > fieldB`) inline inside the `WHERE` clause, you have two ways to perform field-to-field comparisons depending on whether you are querying a Workday-delivered/custom reporting data source or an Extend Model Business Object.

### Approach 1: Create a True/False Condition Calculated Field (`cf_...`)

When querying a Workday data source (or an Extend Business Object with reporting enabled) where you want Workday to filter or count rows server-side before returning the response, push the field-to-field comparison into a **True/False Condition** calculated field:

1.  Run the **Create Calculated Field** task in your Workday tenant.
2.  Set the **Business Object** to the primary business object of your data source and select **True/False Condition** as the function.
3.  Configure the comparison so that **Field** is `totalApprovalLevel`, **Operator** is `equal to`, **Comparison Type** is *Value from another field*, and **Comparison Value** is `currentApprovalLevel`.
4.  Save the calculated field and check its **WQL Alias** (for example, `cf_isFinalApprovalLevel`) from its related actions menu (**Calculated Field** > **View WQL Alias**).
5.  Filter against the boolean literal `true` in your WQL `WHERE` clause:

sql

```
SELECT COUNT(workdayID) AS recCount
FROM customApprovalRequests
WHERE cf_isFinalApprovalLevel = true
```

Because `true` is a valid boolean literal on the right-hand side of `=`, WQL executes the filter at the database/index layer and returns only the matching count or rows.

### Approach 2: Select Both Fields and Filter in PMD or Orchestrate

If you are querying an Extend Model Business Object where you do not want to maintain an extra calculated field—or if the narrowed population (after filtering by status, requester, or date range) is already small—filter by your indexed literal conditions in WQL, select both fields, and compare them in your PMD script or Orchestration expression:

sql

```
SELECT workdayID, totalApprovalLevel, currentApprovalLevel
FROM appNamespace_approvalRequests
WHERE status = 'In Progress'
  AND totalApprovalLevel IS NOT EMPTY
  AND currentApprovalLevel IS NOT EMPTY
```

Then evaluate `row.totalApprovalLevel == row.currentApprovalLevel` in PMD script:

javascript

```
var rows = getInProgressApprovals.data ?? [];
var matchingRows = rows.filter(function(row) {
  return row.totalApprovalLevel == row.currentApprovalLevel;
});
var recCount = matchingRows.size();
```

## Choosing Between `COUNT(workdayID)` and `COUNT()`

When aggregating matched records in WQL, pay close attention to how `COUNT` is written:

-   On Extend Model Business Objects and Prism data sources, passing an explicit non-null identifier field such as `SELECT COUNT(workdayID) AS recCount` (or `COUNT(DISTINCT workdayID)`) reliably counts non-empty instances of that field.
-   In standard WQL reference syntax, `COUNT()` takes no arguments (`SELECT location, count() FROM allWorkers GROUP BY location`), while `COUNT(DISTINCT field)` takes a single text or single-instance field. However, several data sources and parser paths reject `COUNT()` without a `GROUP BY` clause or reject `COUNT(field)` without `DISTINCT`. Testing both `SELECT count()` and `SELECT count(workdayID)` in **View WQL Query Result** against your specific data source immediately confirms which form its backing engine expects.

## How to Verify in the Tenant

1.  Open **View WQL Query Result** in your Workday tenant.
2.  Confirm that `SELECT totalApprovalLevel, currentApprovalLevel FROM <dataSource> LIMIT 10` returns both fields with the expected data types.
3.  If using the Calculated Field approach, open the related actions on your new True/False Condition field, copy its exact `cf_...` WQL alias, and run:
    
    sql
    
    ```
    SELECT workdayID, totalApprovalLevel, currentApprovalLevel, cf_isFinalApprovalLevel
    FROM <dataSource>
    WHERE cf_isFinalApprovalLevel = true
    LIMIT 20
    ```
    
4.  Verify that every returned row has `totalApprovalLevel` equal to `currentApprovalLevel` before replacing the field list with `COUNT(workdayID)` or `count()`.

## Sources checked

-   [WQL Reference: WHERE](https://developer.workday.com/documentation/GUID-a9f9f945-baf1-4a7d-9118-db9a8ce49265-enHYPHENus)
-   [WQL Reference: SELECT](https://developer.workday.com/documentation/GUID-85db8d16-4698-4dea-bef2-23223739c8e6-enHYPHENus)
-   [Reference: WQL Aliases](https://developer.workday.com/documentation/ktw1644956621314)
-   [View WQL Query Results](https://developer.workday.com/documentation/GUID-02c163da-f639-4d00-b453-b793a71ba081-enHYPHENus)

## Related guides

[All guides](https://kiweely.com/guides)

-   [### Filtering Empty Related Business Objects in WQL and Guarding Omitted RBO Keys in PMD Checking whether a context-linked Related Business Object (RBO) is empty in a WQL WHERE clause can throw “Field: ... can only be used as a related business object field (RBO)”, and empty RBOs are omitted entirely from WQL JSON responses. Learn how to filter empty RBOs and guard PMD scripts.](https://kiweely.com/guides/wql-check-rbo-empty-missing-json-keys-pmd)
-   [### Why WQL AVG() Rounds to Whole Numbers and How to Handle Conditional Logic Without CASE WQL does not support ROUND(), CAST(), CASE WHEN, or DECODE(), and its built-in AVG() function rounds integer fields to whole numbers. Learn how to compute exact decimal averages with SUM() and COUNT() and how to implement conditional boolean logic in WQL.](https://kiweely.com/guides/wql-avg-integer-rounding-conditional-logic-without-case)
-   [### What is Workday Query Language (WQL), and how do you write and run a query? Workday Query Language (WQL) is Workday’s SQL-like language for reading data from data sources and fields instead of reports. You need the Workday Query Language domain in the System functional area; an external caller also needs an API client with System scope.](https://kiweely.com/guides/workday-wql)
-   [### Why does my Workday WQL query fail? The exact error messages and how to fix each one Workday has no WQL message worded ‘instance set invalid for prompt’. A rejected prompt value returns ‘Invalid Parameter Values for parameter’ or ‘does not meet the restrictions defined for this field’. This page quotes each common error as Workday returned it, with the fix.](https://kiweely.com/guides/wql-error-messages)

### More guides on WQL

[All 31 guides](https://kiweely.com/guides#wql)

-   [Fixing WQL “Specify a valid report field” and HTTP 500 Errors When an ISU Queries Calculated Fields](https://kiweely.com/guides/wql-calculated-field-isu-specify-valid-report-field-500)
-   [WQL 500-Instance Related Business Object Limit and Large IN (...) Filter Limits](https://kiweely.com/guides/wql-500-rbo-instances-per-row-large-in-filter-limits)
-   [Fixing WQL HTTP 400 “Parms are required for the fields or data source in the query”](https://kiweely.com/guides/wql-400-parms-are-required-for-fields-or-data-source)
-   [Custom Agent Actions that call Workday SOAP, REST and WQL](https://kiweely.com/guides/workday-custom-agent-actions-soap-rest-wql)
-   [Running WQL in Orchestrate as an integration system user: the security it needs](https://kiweely.com/guides/workday-orchestrate-wql-as-isu)
-   [WQL Cheat Sheet: Workday Query Language Syntax, Data Sources and Working Examples](https://kiweely.com/guides/workday-wql-cheat-sheet)
-   [Workday Prism Analytics vs. WQL vs. Custom Reports: Joining External and Tenant Data](https://kiweely.com/guides/workday-prism-analytics-vs-wql)
-   [Should I use RaaS, WQL or the REST API to extract data from Workday?](https://kiweely.com/guides/workday-raas-wql-rest)

### From the blog on WQL

[All posts](https://kiweely.com/blog)

-   [Build vs. Buy a Workday MCP Server: OAuth 2.1, SOAP, WQL, and Twice-Yearly Releases](https://kiweely.com/blog/build-vs-buy-workday-mcp-server-engineering-cost)
-   [What happens after ChatGPT writes your WQL query](https://kiweely.com/blog/after-chatgpt-writes-your-wql)
-   [Answering Executive Span-of-Control and Headcount Questions Live from Workday](https://kiweely.com/blog/executive-org-span-of-control-attrition-questions-live-workday)

## Let Workday check the work.

Kiweely writes WQL and builds orchestrations in your own tenant, and Workday, not Kiweely, says whether they passed.

[Start for free](https://kiweely.com/download) [See how it works](https://kiweely.com/vine/how-it-works)

## Get the next guide in your inbox.

One email a month with new guides and one Extend tip. Nothing else.
