How can I from SQL Queries when using Aggregate functions like count, min, max etc?

How can I from SQL Queries when using Aggregate functions like count, min, max etc?

How to Form SQL Queries When Using Aggregate Functions (COUNT, MIN, MAX, SUM, AVG)

Points to remember before adding a Query Monitor:

Notes
  • The query must be entered as a single line without Line breaks.
  • A maximum of 5 queries can be configured in a single Database Query Monitor.
  • Multiple queries should be separated using a new line delimiter.
  • The monitor displays a maximum of 50 rows in the output. This limit can be changed under Settings of Applications Manager -> Performance Polling -> Optimize Data Collection -> Choose Monitor Type as Script / Database Query Monitor -> "Query monitor row count" text box. Increasing the limit to higher number will increase load to Applications Manager monitoring behavior.
  • If the query returns multiple columns, we recommend selecting an unique ID columns or non-volatile string column as the Primary Key. If no suitable string column exists, add a dummy identifier as shown below.


Why do I get the "without an identifier" error upon adding a Query Monitor?


Applications Manager requires every Database Query Monitor to have an Identifier (Primary Key) that uniquely identifies each result row.

If your query returns only aggregate values (such as COUNT, SUM, MIN, MAX, or AVG), there is no identifier available, resulting in the "without an identifier" error.

When is a dummy identifier required?

A dummy identifier is required only if your query does not already return a unique column.

Query ResultAction
Only aggregate function(s)Add a dummy identifier.
Returns a unique column (Primary Key, ID, Session ID, etc.)Use that column as the Primary Key. No dummy identifier is required.
Returns a non-unique column (Status, Category, Type, etc.)Add a dummy identifier or use a unique column instead.


How to add a dummy identifier?

Oracle / MySQL / Sybase:

SELECT 'Number of Pending Tasks', COUNT(*) AS TotalCount FROM app_pending_tasks

Use 'Number of Pending Tasks' as the Primary Key.

SQL Server / PostgreSQL / Db2 / Kingbase:
SELECT 'Number of Pending Tasks' AS TaskName, COUNT(*) AS TotalCount FROM app_pending_tasks

Use TaskName as the Primary Key.

Example

❌ Incorrect

SELECT COUNT(*) FROM app_pending_tasks

✅ Correct

SELECT 'Number of Pending Tasks' AS TaskName, COUNT(*) AS TotalCount FROM app_pending_tasks


Before Saving the Query

Verify that:

  • Your query returns either:
    • a unique column (such as an ID or Primary Key), or
    • a dummy identifier (string literal).
  • The identifier is configured as the Primary Key in the Database Query Monitor's output table.
  • If your query uses GROUP BY, ensure the identifier column is included in the GROUP BY clause.

Still seeing the error?

If the issue persists after following the above guidelines, contact Applications Manager Support with:

  • The complete SQL query.
  • Add Monitor/Edit Monitor/Monitor Page screenshot.
  • The database type (Oracle, SQL Server, PostgreSQL, MySQL, etc.).
  • The Applications Manager build number.