117 views
2 2 votes

Consider:

SQL Statement $\mathbf{1}$

$\mathrm{SELECT\ *}$ $\mathrm{FROM\ R}$ $\mathrm{UNION}$ $\mathrm{SELECT\ *}$ $\mathrm{FROM\ R}$;


SQL Statement $\mathbf{2}$

$\mathrm{SELECT\ *}$ $\mathrm{FROM\ R}$;


What is the necessary and sufficient condition for SQL $1$ and SQL $2$ to always produce identical results for table $\mathrm{R}$?

  1. No row of $\mathrm{R}$ contains a $\mathrm{NULL}$.
     
  2. $\mathrm{R}$ contains zero rows.
     
  3. $\mathrm{R}$ contains no duplicate rows.
     
  4. $\mathrm{R}$ contains exactly one column.

1 Answer

0 0 votes

 

Therefore the two results differ whenever $\mathrm{R}$ contains duplicate tuples.

If $\mathrm{R}$ contains no duplicate rows, removing duplicates changes nothing.

Hence,

$\mathrm{SQL\ 1}=\mathrm{SQL\ 2}$ exactly when $\mathrm{R}$ has no duplicate rows.

So C is both necessary and sufficient.

Hence,

Answer : $\boxed{\mathrm{C}}$

Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
128
128 views
GO Classes asked Sep 30
128 views
The database contains:$\mathrm{Users}(\mathrm{uid},\mathrm{name},\mathrm{dob},\mathrm{user\_type})$$\mathrm{Posts}(\mathrm{pid},\mathrm{folder},\mathrm{summary})$$\mathrm...
3 3 votes
1 1 answer
154
154 views
GO Classes asked Sep 30
154 views
The Adjacency List table stores the data for the tree structure shown below. Which SQL keyword should be inserted at $\mathbf{[a]}$ to retrieve the leaf nodes of the tree...
2 2 votes
1 1 answer
123
123 views
GO Classes asked Sep 30
123 views
Consider the following $\mathrm{Product}$ table:$$\begin{array}{|c|c|c|c|} \hline \mathrm{ProductID} & \mathrm{Product} & \mathrm{SupplierID} & \mathrm{UnitPrice} \\ \hli...
2 2 votes
1 1 answer
125
125 views
GO Classes asked Sep 30
125 views
Let $\mathrm{R}$ and $\mathrm{S}$ be relations.For which of the following relational operations is it not necessary that $\mathrm{R}$ and $\mathrm{S}$ be union-compatible...