MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

SQL

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The SQL statement to count distinct rows from a column is,
A
select COUNT DISTINCT columnname AS total ____ rows from tablename;
B
select (COUNT DISTINCT columnname) AS total ____ rows from tablename;
C
select DISTINCT columnname AS total ____ rows from tablename;
D
select COUNT (DISTINCT) AS total ____ rows from tablename;
Explanation: 

Detailed explanation-1: -SELECT COUNT (DISTINCT item num) FROM items; If the COUNT DISTINCT function encounters NULL values, it ignores them unless every value in the specified column is NULL. If every column value is NULL, the COUNT DISTINCT function returns zero (0).

Detailed explanation-2: -To count the number of different values that are stored in a given column, you simply need to designate the column you pass in to the COUNT function as DISTINCT . When given a column, COUNT returns the number of values in that column. Combining this with DISTINCT returns only the number of unique (and non-NULL) values.

Detailed explanation-3: -The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

Detailed explanation-4: -COUNT(*) with GROUP BY returns the number of rows in each group. This includes NULL values and duplicates. COUNT(ALL <expression>) evaluates expression for each row in a group, and returns the number of nonnull values.

There is 1 question to complete.