Machine-translated by Google. Questions are authored in English.
Top

Discussion

A subquery in an SQL SELECT statement:

  • A.can only be used with two tables.
  • B.can always be duplicated by a join.
  • C.has a distinct form that cannot be duplicated by a join.
  • D.cannot have its results sorted using ORDER BY.

Answer: C

Correct answer: has a distinct form that cannot be duplicated by a join.

Many subqueries can be rewritten as joins, but not all. A correlated EXISTS or NOT EXISTS, and a comparison against an aggregate of a related set - WHERE salary > (SELECT AVG(salary) FROM emp) - have no direct join equivalent.

The reason is that a join combines rows while a subquery can compute a value or test existence without producing rows. Subqueries are also not limited to two tables, and their outer query can certainly be sorted with ORDER BY.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.