Which of the following statement(s) is/are correct regarding COUNT functions…

2021

Which of the following statement(s) is/are correct regarding COUNT functions in Structured Query Language of Relational Database Management System? I. COUNT(* ) is used to count the number of values in a column. II. COUNT() is used to count the number of rows of the query result.

Answer: D. Neither I nor IIConceptSQL aggregate functions reduce a set of input rows to a single result. COUNT(*) counts rows, whereas COUNT(expression) counts rows for which the…

  1. A.

    Only I

  2. B.

    Only II

  3. C.

    Both I and II

  4. D.

    Neither I nor II

Attempted by 2289 students.

Show answer & explanation

Correct answer: D

Concept

SQL aggregate functions reduce a set of input rows to a single result. COUNT(*) counts rows, whereas COUNT(expression) counts rows for which the expression is not NULL.

A function call must also follow valid SQL syntax: empty COUNT() is not a standard COUNT form; an argument such as * or an expression is required.

Application

  1. For Statement I, COUNT(*) is row-oriented. It counts every row that survives the query filters, even when a particular column contains NULL, so it does not mean the count of non-NULL values in one named column.

  2. For Statement II, COUNT() supplies no argument. The standard forms are COUNT(*) and COUNT(expression), so empty COUNT() is not the syntax used to count query-result rows.

Cross-check

SQL form

What it counts

COUNT(*)

All rows retained by the query

COUNT(MARKS)

Rows whose MARKS value is not NULL

With rows (MARKS = 80), (MARKS = NULL), and (MARKS = 65), COUNT(*) returns 3 while COUNT(MARKS) returns 2.

This contrast confirms that Statement I assigns column-value behavior to COUNT(*), while Statement II uses an empty call instead of COUNT(*).

Contrast

  • Only I represents the truth pattern I = true and II = false.

  • Only II represents the truth pattern I = false and II = true.

  • Both I and II represents the truth pattern I = true and II = true.

  • Neither I nor II represents the truth pattern I = false and II = false.

Result

Therefore the answer is Neither I nor II.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…