Single Row Function / Multiple Row Function
Single Row Functions
Operate on one row at a time and return one result per row, regardless of how many rows the query processes — for example, UPPER(name) or ROUND(salary, 2).
Multiple Row (Aggregate) Functions
Operate across a group of rows and return a single summarized result — for example, COUNT(*), SUM(salary), AVG(salary), MAX(salary), and MIN(salary).
Using GROUP BY
Aggregate functions are often combined with GROUP BY to summarize data per category, e.g. SELECT department, COUNT(*) FROM employees GROUP BY department;
Why the Distinction Matters for Testing
Knowing which type of function to use lets testers quickly verify things like total record counts, sums, or per-row transformations when validating data against expected results.
Categories of Single Row Functions
Single row functions are grouped by the kind of data they work on. Names differ slightly between databases, so the examples below note common variants.
| Category | Examples | Typical use in testing |
|---|---|---|
| Character | UPPER, LOWER, TRIM, SUBSTR/SUBSTRING, LENGTH/LEN | Check that names are stored without extra spaces |
| Number | ROUND, TRUNC, MOD, ABS | Verify rounding of prices and taxes |
| Date | SYSDATE, CURRENT_DATE, DATEDIFF, ADD_MONTHS | Confirm expiry dates and ages |
| Conversion | CAST, TO_CHAR, TO_DATE, CONVERT | Compare values stored as text with real numbers |
| General / null handling | COALESCE, NVL, IFNULL, CASE | Replace missing values before comparison |
Validation Queries a Tester Actually Writes
Here are a few realistic checks on an employees table after a data migration. Each one targets a specific kind of defect.
-- Names saved with leading or trailing spaces (single row function)
SELECT id, name
FROM employees
WHERE name <> TRIM(name);
-- Emails not stored in lower case
SELECT id, email
FROM employees
WHERE email <> LOWER(email);
-- Row count and salary total must match the source system
SELECT COUNT(*) AS total_rows, SUM(salary) AS total_salary
FROM employees;
-- Departments with more than 50 people (aggregate + HAVING)
SELECT department, COUNT(*) AS headcount
FROM employees
GROUP BY department
HAVING COUNT(*) > 50;
-- Duplicate employee codes
SELECT emp_code, COUNT(*) AS copies
FROM employees
GROUP BY emp_code
HAVING COUNT(*) > 1;
The first two queries run a function on every row and compare it with the stored value. The last three collapse many rows into one result per group, which is ideal for reconciling totals between systems.
WHERE vs HAVING and How NULLs Behave
WHERE filters individual rows before grouping, so it can use single row functions but not aggregates. HAVING filters groups after aggregation, so it is where conditions like COUNT(*) > 1 belong. Writing WHERE COUNT(*) > 1 produces an error.
Aggregate functions skip NULL values, with one exception: COUNT(*) counts every row. This difference matters when you test:
COUNT(*)counts all rows;COUNT(bonus)counts only rows where bonus is not NULL.AVG(bonus)divides by the non-null count, so it may be higher than you expect. UseAVG(COALESCE(bonus, 0))if missing bonuses should count as zero.SUMof a column that is entirely NULL returns NULL, not zero.
Mistakes and a Tester's Checklist
- Mixing grouped and ungrouped columns. Every selected column that is not aggregated must appear in
GROUP BY. - Forgetting that functions differ by database.
NVLis Oracle,IFNULLis MySQL,ISNULLis SQL Server;COALESCEworks almost everywhere. - Wrapping indexed columns in functions on large tables. It can force a full scan and slow your validation query.
- Comparing totals without matching filters. Source and target counts must use the same date range and status rules.
When validating data, check row counts, key totals, duplicates, nulls in mandatory columns and formatting of text fields. Those five checks catch most migration defects.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.