SQL Dialects and Built-in Functions Questions

Portability and idiom differences across SQL engines (PostgreSQL, Redshift, MySQL, SQL Server, and others), plus fluent use of built-in string, date/time, and type-conversion functions. Covers dialect-specific syntax, function availability, and writing queries that behave predictably across platforms. Relevant when candidates move between database ecosystems.

MediumTechnical
132 practiced

Write a SQL query that samples 100 random rows from a logs table in a way that is reproducible (i.e., deterministic sampling given the same seed). Provide the SQL for PostgreSQL (using TABLESAMPLE or ORDER BY random() with a seed) or for a database that supports a seeded random function. Explain trade-offs between TABLESAMPLE and ORDER BY RAND()/random().

MediumTechnical
129 practiced

Write a SQL query to find rows in events where the payload JSON column contains a key user_id equal to '42'. Provide examples for both PostgreSQL JSONB (payload->>'user_id' = '42') and BigQuery JSON_EXTRACT_SCALAR. Explain any subtle differences in null-handling or type casting between the two approaches.

MediumTechnical
95 practiced

In PostgreSQL you want to search emails using a regular expression to find addresses that end with '.edu' or '.org'. Write the SQL using POSIX regex operators (~ or ~*) and explain the difference between the case-sensitive and case-insensitive regex operators in Postgres.

HardTechnical
72 practiced

Events include a JSON array of product_ids purchased in a session:

sessions(session_id INT, user_id INT, products JSON)

Write SQL (for a JSON-capable engine such as Postgres or BigQuery) to explode the array and compute product-level purchase counts across sessions. Address empty arrays and NULL products explicitly and discuss indexing or storage changes to optimize this pattern.

MediumTechnical
148 practiced

Explain how data types affect aggregation results. Scenario: an orders.amount column is stored as INT and summing many rows causes overflow. Describe how to detect and fix type/coercion problems in SQL aggregations and whether casting to DECIMAL or BIGINT is preferable.

Unlock Full Question Bank

Get access to all 8 SQL Dialects and Built-in Functions interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.