Questions
26 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?
26 / 30

How can you use JSON_EXTRACT() and JSON_CONTAINS() to work with JSON data in MySQL?

Working with JSON Data Using JSON_EXTRACT() and JSON_CONTAINS()

MySQL provides native JSON functions to query and manipulate JSON data stored in JSON columns. Two commonly used functions are JSON_EXTRACT() and JSON_CONTAINS().

1. JSON_EXTRACT()
  1. 1

    Retrieves data from a JSON document using a JSON path expression.

  2. 2

    Returns the value at the specified path as JSON.

  3. 3

    Can extract nested values, arrays, or objects.

JSON_EXTRACT() Example
2. JSON_CONTAINS()
  1. 1

    Checks whether a specific JSON value exists within a JSON document.

  2. 2

    Returns 1 if the value exists, 0 otherwise.

  3. 3

    Supports optional path argument to search within nested structures.

JSON_CONTAINS() Example
3. Key Usage Notes
  1. 1

    JSON_EXTRACT() is read-only and ideal for retrieving values from JSON columns.

  2. 2

    JSON_CONTAINS() is useful in WHERE clauses to filter rows containing specific JSON data.

  3. 3

    Both functions can work with indexes on generated columns to improve performance.

  4. 4

    JSON paths use the $ symbol as the root and dot notation or array indices to traverse the structure.

In summary: Use JSON_EXTRACT() to retrieve specific values from JSON documents, and JSON_CONTAINS() to test whether certain values exist in JSON columns, enabling powerful filtering and querying of semi-structured data in MySQL.

Difficulty: 6/10
Topics: JSON extraction, JSON containment, MySQL indexing

Scenario Questions

0-2 years experience
  1. 1

    We have a table orders with a JSON column details that stores an object with a field status. How would you write a query to return all rows where status equals 'shipped' using JSON_EXTRACT()?

  2. 2

    Given a JSON column profile containing an array like ["admin","editor"], how can you check if the array contains the value 'admin' using JSON_CONTAINS()?

2-5 years experience
  1. 1

    Our feature needs to filter users whose preferences JSON field includes a nested key notifications.email set to true. The current query using JSON_EXTRACT() returns no rows, but the data looks correct. Walk me through how you'd debug this and what might be wrong.

  2. 2

    We decided to add a generated column that indexes the type field inside a JSON column for faster lookups. Explain how you'd use JSON_EXTRACT() in the generated column definition and discuss any limitations.

5-8 years experience
  1. 1

    Our service stores large JSON payloads (up to 10KB) in MySQL and frequently runs queries with JSON_CONTAINS() to check for specific tags. What performance concerns arise, and how would you mitigate them at the schema or query level?

  2. 2

    We need to migrate a legacy schema that stored key‑value pairs in separate columns to a single JSON column, but we still need to support existing queries that use JSON_EXTRACT(). How would you design a migration strategy that minimizes downtime and ensures backward compatibility?

8+ years experience
  1. 1

    Looking ahead, we plan to shard our MySQL cluster and replicate data across regions, while heavily relying on JSON fields for flexible data models. What architectural considerations should we keep in mind regarding JSON_EXTRACT() and JSON_CONTAINS() usage, especially concerning index portability and query consistency?

  2. 2

    Our organization wants to standardize JSON handling across multiple services, some using MySQL, others using PostgreSQL. How would you propose an abstraction layer or guidelines to ensure consistent behavior for extracting and checking JSON content, given differences in functions like JSON_EXTRACT() vs ->> operators?

Follow-up Questions

  • What index types does MySQL provide for JSON columns?
  • How does JSON_EXTRACT() differ from the -> operator?
  • How would you handle inconsistent JSON structures across rows?