Based on the SQLD exam syllabusReport an error
IN, ANY, ALL, and EXISTS. > ANY means greater than the minimum, > ALL means greater than the maximum, and if the subquery is empty, ALL is true for every row.ROLLUP, 2ⁿ for CUBE, and for GROUPING SETS just the number you list. The number of result rows is the sum of the group counts produced by each grouping set.RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.We re-lay Subject 2 (SQL Basics and Applications, plus management statements), learned in W3 to W7, focusing on confusing pairs. The NULL and COUNT pitfalls are in W8 Day 1, the execution-order and join pitfalls in W8 Day 2, and the Oracle vs SQL Server differences in W8 Day 3, so they are not covered here.
| Category | Representative functions | Where results diverge |
|---|---|---|
| Character | SUBSTR, INSTR, LENGTH, TRIM, LTRIM, RTRIM, LPAD, RPAD, REPLACE | Positions count from 1. If SUBSTR's start is negative, it counts from the end. INSTR returns 0 if not found |
| Numeric | ROUND, TRUNC, CEIL, FLOOR, MOD, ABS, SIGN | If the digit count is negative, it cuts in the integer part. CEIL is the larger integer, FLOOR the smaller |
| Date | SYSDATE, ADD_MONTHS, MONTHS_BETWEEN, LAST_DAY, NEXT_DAY | Date − date = days, date + date = error. If you ADD_MONTHS to a month-end, the result is also a month-end |
| Conversion | TO_CHAR, TO_DATE, TO_NUMBER | These three are Oracle's explicit conversion functions (the standard CAST can also be used). Implicit conversion gives results that depend on NLS settings |
| NULL | NVL, NVL2, NULLIF, COALESCE | NVL2(a, b, c) gives b if a is not NULL. NULLIF(a, b) gives NULL if equal, a if different |
| Conditional | CASE, DECODE | CASE uses only the first true WHEN. DECODE treats NULL and NULL as equal |
| Multi-row | COUNT, SUM, AVG, MAX, MIN | One value per group. Except for COUNT(*), they skip NULL |
We run the cases where signs and digit counts get mixed up in numeric and character functions all at once.
SELECT SUBSTR('SQLDEVELOPER', -3, 2) AS SUB, INSTR('SQLDEVELOPER', 'E', 1, 2) AS INS, ROUND(45.678, -1) AS RND, TRUNC(45.678, 1) AS TRC, CEIL(-1.2) AS CL, FLOOR(-1.2) AS FL, MOD(-7, 3) AS MD FROM DUAL;SU INS RND TRC CL FL MD
-- ---------- ---------- ---------- ---------- ---------- ----------
PE 7 50 45.6 -1 -2 -1SUBSTR(…, -3, 2) is two characters starting from the third character from the end, P. INSTR(…, 'E', 1, 2) is the position 7 of the second E.ROUND(45.678, -1) rounds at the ones place to give 50, and TRUNC(45.678, 1) keeps up to the first decimal place to give 45.6.| Position | Name | Restriction |
|---|---|---|
| SELECT clause | Scalar subquery | Must return only one row and one column |
| FROM clause | Inline view | ORDER BY can be used |
| WHERE, HAVING clause | Nested subquery | ORDER BY cannot be used (ORA-00907) |
| Operator | Meaning | If the subquery result is empty |
|---|---|---|
=, >, < … | Single-row comparison. If several rows come, ORA-01427 | No comparison target, so 0 rows |
IN | Equal to one of the list | 0 rows |
> ANY | Greater than at least one = greater than the minimum | 0 rows |
> ALL | Greater than all = greater than the maximum | Every row is true |
EXISTS | True if the subquery produces even one row | False |
Based on the department 30 salaries (950, 1250, 1250, 1500, 1600, 2850), we count the result rows of three operators side by side. The last column is > ALL based on the nonexistent department 99.
SELECT (SELECT COUNT(*) FROM EMP WHERE SAL > ANY (SELECT SAL FROM EMP WHERE DEPTNO = 30)) AS GT_ANY, (SELECT COUNT(*) FROM EMP WHERE SAL > ALL (SELECT SAL FROM EMP WHERE DEPTNO = 30)) AS GT_ALL, (SELECT COUNT(*) FROM EMP WHERE SAL IN (SELECT SAL FROM EMP WHERE DEPTNO = 30)) AS IN_CNT, (SELECT COUNT(*) FROM EMP WHERE SAL > ALL (SELECT SAL FROM EMP WHERE DEPTNO = 99)) AS ALL_EMPTY FROM DUAL; GT_ANY GT_ALL IN_CNT ALL_EMPTY
---------- ---------- ---------- ----------
12 4 6 14> ANY is the 12 employees greater than 950. Only JAMES at 950 and SMITH at 800 drop out.> ALL is the 4 employees greater than 2850: KING, FORD, SCOTT, and JONES.> ALL has no value to violate "greater than all," so all 14 employees are true.| Operator | Result | Duplicates |
|---|---|---|
UNION | Union | Removed |
UNION ALL | Concatenation | Kept |
INTERSECT | Intersection | Removed |
MINUS | Difference, the second removed from the first | Removed |
We compare the row counts of the four operators using the department 10 jobs (CLERK, MANAGER, PRESIDENT) and the department 20 jobs (CLERK 2, ANALYST 2, MANAGER 1).
SELECT (SELECT COUNT(*) FROM (SELECT JOB FROM EMP WHERE DEPTNO = 10 UNION SELECT JOB FROM EMP WHERE DEPTNO = 20)) AS U, (SELECT COUNT(*) FROM (SELECT JOB FROM EMP WHERE DEPTNO = 10 UNION ALL SELECT JOB FROM EMP WHERE DEPTNO = 20)) AS UA, (SELECT COUNT(*) FROM (SELECT JOB FROM EMP WHERE DEPTNO = 10 INTERSECT SELECT JOB FROM EMP WHERE DEPTNO = 20)) AS I, (SELECT COUNT(*) FROM (SELECT JOB FROM EMP WHERE DEPTNO = 10 MINUS SELECT JOB FROM EMP WHERE DEPTNO = 20)) AS M FROM DUAL; U UA I M
---------- ---------- ---------- ----------
4 8 2 1Count the rows in two steps. First expand the list of grouping sets, then add the group counts that come out of each grouping set.
| Syntax | Expanded grouping sets | Number of sets |
|---|---|---|
ROLLUP(A, B) | (A, B), (A), () | n + 1 = 3 |
CUBE(A, B) | (A, B), (A), (B), () | 2ⁿ = 4 |
GROUPING SETS(A, B) | (A), (B) | 2, as listed |
GROUPING SETS((A, B), ()) | (A, B), () | 2 |
The group counts in EMP are 9 (DEPTNO, JOB) combinations, 3 DEPTNO values, 5 JOB values, and 1 grand total.
SELECT (SELECT COUNT(*) FROM (SELECT DEPTNO, JOB FROM EMP GROUP BY DEPTNO, JOB)) AS BASE, (SELECT COUNT(*) FROM (SELECT DEPTNO, JOB FROM EMP GROUP BY ROLLUP(DEPTNO, JOB))) AS RLP, (SELECT COUNT(*) FROM (SELECT DEPTNO, JOB FROM EMP GROUP BY CUBE(DEPTNO, JOB))) AS CUB, (SELECT COUNT(*) FROM (SELECT DEPTNO, JOB FROM EMP GROUP BY GROUPING SETS(DEPTNO, JOB))) AS GSETS FROM DUAL; BASE RLP CUB GSETS
---------- ---------- ---------- ----------
9 13 18 8| Syntax | Calculation | Rows |
|---|---|---|
GROUP BY DEPTNO, JOB | 9 | 9 |
ROLLUP(DEPTNO, JOB) | 9 + 3 + 1 | 13 |
CUBE(DEPTNO, JOB) | 9 + 3 + 5 + 1 | 18 |
GROUPING SETS(DEPTNO, JOB) | 3 + 5 | 8 |
ROLLUP(JOB, DEPTNO), the subtotals are 5 per JOB, so it is 9 + 5 + 1 = 15 rows. CUBE gives the same set of rows regardless of order.GROUPING(column) is 1.We line up department 30 by salary ascending. MARTIN and WARD tie at 1250. The last column is a running sum with only ORDER BY given in OVER.
SELECT ENAME, SAL, RANK() OVER (ORDER BY SAL) AS RNK, DENSE_RANK() OVER (ORDER BY SAL) AS DRNK, ROW_NUMBER() OVER (ORDER BY SAL, ENAME) AS RN, SUM(SAL) OVER (ORDER BY SAL) AS RUN_SUM FROM EMP WHERE DEPTNO = 30 ORDER BY SAL, ENAME;ENAME SAL RNK DRNK RN RUN_SUM
---------- ---------- ---------- ---------- ---------- ----------
JAMES 950 1 1 1 950
MARTIN 1250 2 2 2 3450
WARD 1250 2 2 3 3450
TURNER 1500 4 3 4 4950
ALLEN 1600 5 4 5 6550
BLAKE 2850 6 5 6 9400RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, so rows with the same SAL value are added all at once. To accumulate one row at a time, change it to ROWS (W6 Day 2).| Inside OVER | Calculation range |
|---|---|
Empty OVER () | All rows |
PARTITION BY only | The whole partition |
Includes ORDER BY | From the start of the partition up to the current row's value (RANGE) |
LAST_VALUE returning the current row's value (when there are no ties in the sort value) is also due to the same default range. If there are ties, the value of the last row with the same sort value comes out.⚠️ Pitfall: Rank-function questions ask separately for the "rank after a tie" and the "last rank." The last value of RANK is the row count if there is no tie at the very end, and the last value of DENSE_RANK is the number of distinct values.
| Term | Meaning |
|---|---|
START WITH | The root (starting) row condition |
CONNECT BY PRIOR EMPNO = MGR | Goes down to rows whose MGR equals the EMPNO of an already-found row (forward) |
CONNECT BY PRIOR MGR = EMPNO | Goes up to rows whose EMPNO equals the MGR of an already-found row (reverse) |
LEVEL | Depth where the root is 1 |
CONNECT_BY_ISLEAF | 1 if there are no children in that expansion |
CONNECT_BY_ROOT column | The root value of the tree the row belongs to |
SYS_CONNECT_BY_PATH(column, '/') | The path joined from the root to the current row |
ORDER SIBLINGS BY | Keeps the tree shape and sorts only among siblings |
We start from SMITH and go up.
SELECT LEVEL, ENAME, CONNECT_BY_ISLEAF AS LEAF FROM EMP START WITH ENAME = 'SMITH' CONNECT BY PRIOR MGR = EMPNO ORDER BY LEVEL; LEVEL ENAME LEAF
---------- ---------- ----------
1 SMITH 0
2 FORD 0
3 JONES 0
4 KING 1PIVOT (aggregate FOR column IN (value AS alias, …)) turns row values into column headers. All the remaining columns not used in the aggregate or FOR become the grouping basis, so you reduce the columns through an inline view before passing it in.UNPIVOT (value_column FOR name_column IN (column, …)) does the opposite and turns columns into rows. NULL rows are discarded by default, and given INCLUDE NULLS they are kept.SELECT * FROM (SELECT DEPTNO, JOB FROM EMP) PIVOT (COUNT(*) FOR DEPTNO IN (10 AS D10, 20 AS D20, 30 AS D30)) ORDER BY JOB;JOB D10 D20 D30
--------- ---------- ---------- ----------
ANALYST 0 2 0
CLERK 1 2 1
MANAGER 1 1 1
PRESIDENT 1 0 0
SALESMAN 0 0 4| Function | What it returns |
|---|---|
REGEXP_LIKE(string, pattern) | A condition (used in WHERE). True if the pattern is anywhere |
REGEXP_SUBSTR(string, pattern, start, nth) | The matched substring |
REGEXP_INSTR | The matched position (0 if none) |
REGEXP_REPLACE | The replaced string. Use \1 to reuse a parenthesized group |
REGEXP_COUNT | The number of matches |
SELECT REGEXP_SUBSTR('A12-B345-C6', '[0-9]+', 1, 2) AS SUB, REGEXP_COUNT('A12-B345-C6', '[0-9]') AS CNT, REGEXP_INSTR('A12-B345-C6', '-') AS INS, REGEXP_REPLACE('2026-11-04', '(\d+)-(\d+)-(\d+)', '\3/\2/\1') AS REP FROM DUAL;SUB CNT INS REP
--- ---------- ---------- ----------
345 6 4 04/11/2026[0-9]+ is 345. [0-9] is one digit character, so the count is 6.^…$.| Category | Commands | Confirmed in Oracle |
|---|---|---|
| DML | INSERT, UPDATE, DELETE, MERGE (including SELECT) | Confirmed only on COMMIT, can ROLLBACK |
| DDL | CREATE, ALTER, DROP, RENAME, TRUNCATE | Implicit COMMIT before and after execution |
| DCL | GRANT, REVOKE | Immediately on execution |
| TCL | COMMIT, ROLLBACK, SAVEPOINT | — |
ROLLBACK TO savepoint cancels only what came after that savepoint, and savepoints created after it disappear.We compare the three statements by "what remains."
| Question | DELETE | TRUNCATE | DROP |
|---|---|---|---|
| Category | DML | DDL | DDL |
| Can it delete only some rows? | Yes, with WHERE | No | No |
| ROLLBACK in Oracle | Possible | Not possible | Not possible |
| Table structure after deleting | Remains | Remains | Gone (ORA-00942) |
| Storage space | Stays | Returned | Returned |
| Constraint | NULL | Duplicates | Per table |
|---|---|---|---|
| PRIMARY KEY | Not allowed | Not allowed | One |
| UNIQUE | Multiple allowed | Not allowed | Several |
| NOT NULL | Not allowed | Allowed | Per column |
| CHECK | Passes if the condition is NULL | Allowed | Several |
| FOREIGN KEY | Allowed | Allowed | Several (only parent PK or UNIQUE values) |
ON DELETE CASCADE deletes the children too, and ON DELETE SET NULL changes the child FK to NULL.CREATE TABLE … AS SELECT), of the constraints only NOT NULL comes along.WITH GRANT OPTION on object privileges cascades on REVOKE, while WITH ADMIN OPTION on system privileges does not cascade.Source: the exam information table in content/aws-certs/sqld/README.md (introduction to the Data Qualification SQL certificate, dataq.or.kr, confirmed 2026-11-03).
IN, ANY, ALL, and EXISTS.() is the grand-total set.RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW used when OVER has only ORDER BY. It includes tied rows together.CONNECT BY PRIOR MGR = EMPNO.Click a choice to reveal the answer and explanation.
Question 1
The (DEPTNO, JOB) combinations in EMP number 9. What is the result of SELECT COUNT(*) FROM (SELECT DEPTNO, JOB, COUNT(*) FROM EMP GROUP BY GROUPING SETS ((DEPTNO, JOB), ()));?
Question 2
The department 20 salaries are SCOTT 3000, FORD 3000, JONES 2975, ADAMS 1100, and SMITH 800. In the following SQL, what are the RNK and DRNK values on the JONES row?
SELECT ENAME, RANK() OVER (ORDER BY SAL DESC) AS RNK, DENSE_RANK() OVER (ORDER BY SAL DESC) AS DRNK FROM EMP WHERE DEPTNO = 20;
Question 3
Department 99 does not exist in EMP. What is the result of SELECT COUNT(*) FROM EMP WHERE SAL > ALL (SELECT SAL FROM EMP WHERE DEPTNO = 99);?
Question 4
Which statement about DELETE, TRUNCATE, and DROP in Oracle is correct?
Question 5
In the following SQL, what is the LEVEL value on the KING row? (SMITH's manager is FORD, FORD's manager is JONES, JONES's manager is KING, and KING has no manager)
SELECT LEVEL, ENAME FROM EMP START WITH ENAME = 'SMITH' CONNECT BY PRIOR MGR = EMPNO;