Questions
2 of 30
1What are functions and operators in MySQL, and how are they different?
2What is the difference between single-row functions and aggregate functions?
3Give examples of commonly used string functions in MySQL.
4What is the use of the CONCAT() function? How is it different from using ||?
5Explain the difference between NOW(), CURDATE(), and SYSDATE().
6What are arithmetic operators in MySQL? Give examples.
7What is the difference between the = and <=> operators?
8What does the DISTINCT keyword do when used with aggregate functions like COUNT()?
9What is the difference between IFNULL() and COALESCE() functions?
10What are logical operators in MySQL, and how do AND, OR, and NOT work?
11What is the difference between LENGTH() and CHAR_LENGTH() functions?
12How does MySQL handle type conversion when using operators on different data types?
13What is the difference between ROUND(), TRUNCATE(), and FORMAT() functions?
14Explain how CASE and IF() functions can be used for conditional logic.
15What are comparison operators in MySQL, and how are they used with NULL values?
16How do aggregate functions like AVG(), SUM(), and MAX() behave when NULLs are present?
17Explain the use of REGEXP and LIKE operators. What’s the difference between them?
18What are user-defined functions (UDFs), and how do they differ from stored procedures?
19What are the differences between DATE_ADD() and ADDDATE() functions?
20How can you use STR_TO_DATE() and DATE_FORMAT() for converting and displaying date values?
21How does MySQL internally optimize and cache results of deterministic functions?
22What are window functions in MySQL 8.0, and how do they differ from aggregate functions?
23Explain the difference between RANK(), DENSE_RANK(), and ROW_NUMBER() window functions.
24How does MySQL evaluate operator precedence when multiple operators are used in a single expression?
25Can functions be used in the WHERE clause? What are the performance implications?
26How can you use JSON_EXTRACT() and JSON_CONTAINS() to work with JSON data in MySQL?
27What are the performance trade-offs of using scalar functions inside JOIN or GROUP BY clauses?
28Explain how collation affects comparison operators in string functions.
29What are deterministic and non-deterministic functions? How does this affect replication and indexes?
30How would you combine multiple functions and operators to clean, transform, and aggregate data efficiently in one query?
02 / 30

What is the difference between single-row functions and aggregate functions?

Difficulty: 4/10
SQL functions, aggregation, grouping

Single-Row Functions vs. Aggregate Functions in MySQL

MySQL functions can be grouped into two major types based on how they operate on data: single-row functions and aggregate functions. They differ in purpose, behavior, and how many rows they process.

1. What Are Single-Row Functions?
  1. 1

    Single-row functions operate on one row at a time.

  2. 2

    For each input row, they return exactly one output value.

  3. 3

    They do not reduce the number of rows in the result set.

  4. 4

    Used in SELECT, WHERE, ORDER BY, GROUP BY, and HAVING clauses.

  5. 5

    Categories include string, numeric, date/time, conversion, and control functions.

Examples of Single-Row Functions
2. What Are Aggregate Functions?
  1. 1

    Aggregate functions operate on multiple rows and return a single summarized result.

  2. 2

    Used to perform calculations on groups of rows (e.g., totals, averages).

  3. 3

    Often used with GROUP BY to produce results per group.

  4. 4

    If GROUP BY is not used, the entire table is treated as one group.

Examples of Aggregate Functions
3. Key Differences Between Single-Row and Aggregate Functions
  1. 1

    Rows processed: Single-row functions process one row at a time; aggregate functions process multiple rows at once.

  2. 2

    Output: Single-row functions return one result per row; aggregate functions return one result per group.

  3. 3

    Usage: Aggregate functions require GROUP BY if you want results per group; single-row functions do not.

  4. 4

    Effect on rows: Single-row functions do not change the number of rows; aggregate functions reduce rows.

In summary, single-row functions transform individual rows, while aggregate functions summarize multiple rows into a single result.

Scenario Questions

0-2 years experience

  1. 1We need to list each employee's salary and also show the total payroll in the same result. Which type of function would you use for the salary column and which for the total, and why?
  2. 2If you run SELECT MAX(salary) FROM employees; is MAX a single‑row or an aggregate function? What changes if you also select employee_name without adding GROUP BY?
  3. 3How does MySQL treat CONCAT() compared to SUM() when you add a GROUP BY clause on department_id?

2-5 years experience

  1. 1You added a DATE_FORMAT() column to a query that already groups by region, and the result started returning duplicate rows. Explain why this happened and how to correct it.
  2. 2During a bug fix, moving COUNT(*) from a subquery to the outer SELECT changed the result set. What difference between aggregate and scalar functions caused this behavior?
  3. 3Design a report that shows each customer's average order value and also includes that customer's most recent order date. How would you combine single‑row and aggregate functions without breaking grouping rules?

5-8 years experience

  1. 1Our nightly analytics job aggregates millions of rows. We want to replace a custom row‑by‑row calculation with a built‑in aggregate, but some logic still needs per‑row evaluation. How do you decide when to embed a scalar function inside an aggregation versus using a derived table, considering performance and correctness?
  2. 2A legacy view mixes SUM() with IFNULL() on the same expression, causing MySQL to create a temporary table and slow down. Explain how the interaction between aggregate and scalar functions leads to this, and propose a redesign.
  3. 3When scaling a sharded MySQL cluster, we need a global total across shards. Discuss the challenges of using a single aggregate function versus pulling per‑shard scalar results and aggregating in application code.

8+ years experience

  1. 1We are migrating a monolithic MySQL reporting database to a distributed analytics platform. Part of the migration requires rewriting queries that currently mix aggregate functions with non‑aggregated columns. What architectural guidelines would you set to avoid hidden grouping bugs and keep future queries maintainable?
  2. 2Our organization wants to enforce query patterns that prevent misuse of aggregate functions causing full table scans. As a staff engineer, how would you define policies, tooling, and code‑review checks around the distinction between single‑row and aggregate functions across multiple services?

Follow-up Questions

  • Can you show a query that would error because a scalar column is selected alongside an aggregate without GROUP BY?
  • What impact does MySQL have on performance when it must create a temporary table for aggregation?
  • How would you verify that a fix to a grouping issue doesn’t break other parts of the report?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.