Question

Explain why the following two commands produce different results: SELECT DISTINCT COUNT (V_CODE) FROM PRODUCT; SELECT COUNT (

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SELECT DISTINCT COUNT(V_CODE) FROM PRODUCT;

This query will first execute COUNT(V_CODE) which will return a single value. Then the DISTINCT will be applied to that single value. Which means it will display the same value again.

SELECT COUNT (DISTINCT V_CODE) FROM PRODUCT;

This query will COUNT DISTINCT values in the V_CODE column.

For example if SELECT V_CODE FROM PRODUCT; returns a table like this:

V_CODE
Red
Blue
Red
Red
Blue
Blue
Blue

And if you apply SELECT DISTINCT COUNT(V_CODE) FROM PRODUCT; this will return 7 as the output.

Where as if you apply SELECT COUNT (DISTINCT V_CODE) FROM PRODUCT; this will count distinct V_CODES in the table, which means it will return the value 2 as the output.

Add a comment
Know the answer?
Add Answer to:
Explain why the following two commands produce different results: SELECT DISTINCT COUNT (V_CODE) FROM PRODUCT; SELECT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT