Bird
0
0

Which SQL query correctly counts the total number of rows in a table named orders?

easy📝 Conceptual Q2 of 15
SQL - Aggregate Functions
Which SQL query correctly counts the total number of rows in a table named orders?
ASELECT COUNT(*) FROM orders;
BSELECT COUNT(order_id) FROM orders WHERE order_id IS NULL;
CSELECT COUNT(order_id) FROM orders;
DSELECT COUNT(NULL) FROM orders;
Step-by-Step Solution
Solution:
  1. Step 1: Identify query to count all rows

    COUNT(*) counts every row in the table, including those with NULLs.
  2. Step 2: Analyze other options

    COUNT(order_id) counts only non-NULL order_id values; COUNT(NULL) is invalid and returns 0.
  3. Final Answer:

    SELECT COUNT(*) FROM orders; -> Option A
  4. Quick Check:

    COUNT(*) counts all rows [OK]
Quick Trick: Use COUNT(*) to count all rows including NULLs [OK]
Common Mistakes:
MISTAKES
  • Using COUNT(column) to count all rows
  • Using COUNT(NULL) which returns zero
  • Filtering with IS NULL incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes