DEV Community

Pranav Bakare
Pranav Bakare

Posted on

Interview Questions | 10 most important distinctions between concepts in Oracle SQL

Here are the top 10 most important distinctions between concepts in Oracle SQL, covering foundational ideas like GROUP BY vs. PARTITION BY, JOIN types, and other crucial SQL comparisons.


  1. GROUP BY vs. PARTITION BY

GROUP BY: Aggregates data by collapsing rows with identical values in specified columns, typically used with aggregate functions (COUNT, SUM, etc.).

PARTITION BY: Used with window functions to divide data into partitions for calculations without collapsing rows, retaining all original rows.

  1. INNER JOIN vs. OUTER JOIN

INNER JOIN: Returns rows with matching values in both joined tables, excluding rows without matches.

OUTER JOIN: Includes all rows from one or both tables, adding NULL values where matches do not exist. Variants are LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN.

  1. UNION vs. UNION ALL

UNION: Combines results from multiple queries and removes duplicate rows, ensuring unique results.

UNION ALL: Combines results but keeps duplicates, making it faster than UNION as it skips duplicate checking.

  1. RANK vs. DENSE_RANK

RANK: Assigns ranks to rows, with gaps in ranking if there are ties (e.g., 1, 2, 2, 4).

DENSE_RANK: Assigns ranks to rows without gaps in ranking numbers when there are ties (e.g., 1, 2, 2, 3).

  1. ROWNUM vs. ROW_NUMBER

ROWNUM: A pseudo column that assigns a unique row number to each row retrieved, used in basic pagination but only reliable in sequential order.

ROW_NUMBER(): A window function that assigns unique row numbers in a specific order defined by ORDER BY, commonly used for complex row ordering and pagination.

  1. DELETE vs. TRUNCATE

DELETE: Removes rows one at a time, allows a WHERE clause, and can be rolled back if within a transaction.

TRUNCATE: Removes all rows in a table quickly and without logging individual deletions; cannot be rolled back and cannot include a WHERE clause.

  1. WHERE vs. HAVING

WHERE: Filters rows before any aggregation, used to limit rows based on conditions for individual records.

HAVING: Filters aggregated data after a GROUP BY clause, used to apply conditions on groups (e.g., HAVING COUNT(*) > 1).

  1. PRIMARY KEY vs. UNIQUE KEY

PRIMARY KEY: Ensures unique and non-null values for each row in a column or set of columns; each table has only one.

UNIQUE KEY: Ensures unique values in a column or set of columns but allows NULL values and can have multiple unique keys in a table.

  1. IN vs. EXISTS

IN: Checks if a value exists within a list or a subquery result set, often efficient for small lists.

EXISTS: Tests for the existence of rows in a subquery, commonly faster than IN with larger data sets because it stops as soon as a match is found.

  1. VIEW vs. MATERIALIZED VIEW

VIEW: A virtual table representing the result of a query; it does not store data physically.

MATERIALIZED VIEW: A stored subset of data from a query that refreshes at intervals, improving performance for large or complex queries at the cost of storage space.


These distinctions are essential for efficient querying and understanding advanced Oracle SQL operations, allowing you to leverage the right approach based on data and performance needs.

Top comments (0)