CS FundamentalsVery hardGATE CS (PYQ pattern)

Which of the following statements about standard SQL are correct? I. A column alias defined in the SELECT list can be used in ORDER BY. II. A column alias defined in the SELECT list can be used in the WHERE clause of the same query block. III. A SELECT with GROUP BY may not list a non-aggregated column that is neither grouped nor functionally dependent on the grouping columns. IV. HAVING may use an aggregate that does not appear in the SELECT list.

  1. A. I and II only
  2. B. II, III and IV only
  3. C. I and III only
  4. D. I, III and IV only

Correct answer: D. I, III and IV only

WHERE is evaluated before the SELECT list, so aliases are not visible there (II is false). ORDER BY runs after SELECT and may use aliases, the grouping rule in III is the standard one, and HAVING can filter on any aggregate.

More DBMS and SQL questions

Exams that ask this topic