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().

EasyTechnical
72 practiced

Technical task (SQL): Given a table events(user_id INT, occurred_at TIMESTAMP), write a query to compute Daily Active Users (DAU) for the last 30 days. Include timezone handling assuming occurred_at is UTC and the business operates in America/Los_Angeles. Return columns date (in America/Los_Angeles) and dau_count. Use ANSI SQL or state which dialect you target.

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.

EasyTechnical
79 practiced

You only have query access to a SQL Server instance (no GUI). Write the T-SQL statements or server properties you would use to determine the server's product version, edition, and engine edition, and explain what each returned field means for operations and licensing.

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.

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.