Correlated Subqueries
A correlated subquery references columns from the outer query. It is evaluated once for each row processed by the outer query to perform row-specific logic.
Open snippet →Read these Intermediate SQL snippets line by line — each one comes with a written breakdown of what the code does and why.
A correlated subquery references columns from the outer query. It is evaluated once for each row processed by the outer query to perform row-specific logic.
Open snippet →A CTE is a temporary result set that you can reference within another statement. It improves readability by breaking down complex queries into logical blocks.
Open snippet →The HAVING clause filters groups created by the GROUP BY clause. Unlike WHERE, which filters individual rows, HAVING filters based on aggregate function results.
Open snippet →Window functions perform calculations across a set of table rows related to the current row. ROW_NUMBER assigns a unique sequential integer to rows within a specific partition.
Transactions ensure multiple operations are treated as a single unit. COMMIT saves all pending changes permanently to the database, ensuring data consistency.
Open snippet →COALESCE takes a list of arguments and returns the first non-null value. It is essential for providing fallback values when dealing with optional columns in a database.
Open snippet →The INTERSECT operator returns only the distinct rows that are present in both the first and second query result sets. It is useful for finding common records across different datasets without usin…
Open snippet →A self-join is a regular join where a table is joined with itself. This is primarily used to query hierarchical data, such as employees and their managers stored in the same table.
Open snippet →A UNIQUE constraint ensures that all values in a column are different across all rows. Unlike a PRIMARY KEY, a table can have multiple UNIQUE constraints, and they allow for data integrity and auto…
Open snippet →The CASE expression allows you to add conditional logic to your SQL queries. It evaluates conditions and returns a value when the first condition is met (like an if-then-else statement).
Open snippet →