This question's explanation and your answers so far.
問65
頻出度★★☆
関係データベースの A 表,B 表がある。A 表,B 表に対して(A∪B),(A∩B)を行った結果は,それぞれ P 表,Q 表及び R 表のどれになるか。ここで,∪は和集合演算,∩は共通集合演算を表す。
A
商品コード
商品名
定価
P001
プリンタ
12,000
P003
PC
65,800
P007
USB ハブ
6,280
P012
OA チェア
14,200
P019
OA デスク
25,600
B
商品コード
商品名
定価
P003
PC
65,800
P007
USB ハブ
6,280
P020
USB メモリ
3,000
P
商品コード
商品名
定価
P003
PC
65,800
P007
USB ハブ
6,280
Q
商品コード
商品名
定価
P001
プリンタ
12,000
P012
OA チェア
14,200
P019
OA デスク
25,600
R
商品コード
商品名
定価
P001
プリンタ
12,000
P003
PC
65,800
P007
USB ハブ
6,280
P012
OA チェア
14,200
P019
OA デスク
25,600
P020
USB メモリ
3,000
出典 平成23年度 秋期 ITパスポート試験 問65
解説
問 65
//
×Incorrectア
This option makes (A∪B) table P and (A∩B) table R, which reverses union and intersection completely. Table P has only 2 rows and is missing P001, P012, and P019 from table A; a union would have to contain at least every row of table A, so it does not hold. Table R, meanwhile, has 6 rows and includes rows found only in table A as well as a row found only in table B (P020), so it cannot be the result of an intersection, which keeps only the rows common to both tables.
×Incorrectイ
This option makes (A∪B) table Q, but table Q {P001, P012, P019} gathers only the rows that are in table A and not in table B — that is, the result of the difference A−B. A union would also have to include P020, which is only in table B, yet table Q contains neither P020 nor P003 and P007, so it is wrong. Making (A∩B) table R does not hold either, because not all 6 of its rows are common to both tables.
○ウ
正解The correct answer is “ウ”: (A∪B) gives table R, and (A∩B) gives table P. The union operation (∪) collects all the rows of two tables and merges duplicate rows into a single row. When the 5 rows of table A {P001, P003, P007, P012, P019} are combined with the 3 rows of table B {P003, P007, P020}, the shared rows P003 and P007 are each merged into one row, so the result is the 6 rows {P001, P003, P007, P012, P019, P020}, which matches table R exactly. The intersection operation (∩), on the other hand, extracts only the rows that exist in both tables. The only rows present in both table A and table B are P003 (PC, 65,800) and P007 (USB hub, 6,280) — just 2 rows — and this matches table P. Therefore “ウ”, with (A∪B) as R and (A∩B) as P, is the correct combination.
×Incorrectエ
The first half of this option, (A∪B) = table R, is correct, but the second half, which makes (A∩B) table Q, is wrong. Table Q {P001, P012, P019} is the set of rows that exist only in table A (the difference A−B), and not a single one of its rows comes from table B. An intersection extracts only the rows that exist in both tables, so the correct result is table P, made up of P003 and P007. Even when the union is right, a wrong intersection makes the combination incorrect.
ここがポイント
Set operations in a relational database: a union (∪) brings together all the rows of two tables with duplicates removed, an intersection (∩) keeps only the rows common to both tables, and a difference (−) keeps only the rows that exist in just one of the tables. All of them can be performed only between tables that have the same column structure (domain).
A quick way to size it up by row count: if A has 5 rows, B has 3 rows, and 2 rows are shared, the union has 5+3−2=6 rows and the intersection has 2 rows. Matching that 6-row table (R) and 2-row table (P) against the answer choices settles the answer. The 3-row table Q corresponds to the difference A−B and is a distractor.