Question:medium

Consider the following table and write the output of the following SQL Queries.

Table : ORDERS

ORDERIDCUSTOMERNAMETOTALAMOUNTDISCOUNTORDERDATE
101Hemant5000102024–03-01
102Neha700015NULL
103Keshav300052024–01-20
104Sandhya4500NULL2023-12-25

Write the output of the following SQL Queries:

I. SELECT CUSTOMERNAME FROM ORDERS WHERE DISCOUNT IS NOT NULL;

II. SELECT CUSTOMERNAME, DISCOUNT FROM ORDERS WHERE DISCOUNT BETWEEN 5 AND 10;

III. SELECT MONTHNAME(ORDERDATE) FROM ORDERS WHERE ORDERDATE IS NOT NULL;

IV. SELECT ORDERID, DAY(ORDERDATE) FROM ORDERS;

Show Hint

Rows with NULL never pass IS NOT NULL or BETWEEN, and BETWEEN includes both end values. MONTHNAME and DAY work on the date part.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Mark the NULL cells first:
In the DISCOUNT column only Sandhya is NULL. In the ORDERDATE column only Neha is NULL.
Most traps in this question come from these two cells.
Two dates carry a long dash in print. We treat them as the usual date form with a hyphen.

Step 2: Row-by-row table for the conditions:
Row 101 Hemant: discount 10, date 2024-03-01.
Row 102 Neha: discount 15, date NULL.
Row 103 Keshav: discount 5, date 2024-01-20.
Row 104 Sandhya: discount NULL, date 2023-12-25.

Step 3: Query I:
DISCOUNT IS NOT NULL is true for rows 101, 102 and 103.
The result has the names Hemant, Neha and Keshav.

Step 4: Query II:
BETWEEN 5 AND 10 means DISCOUNT >= 5 and DISCOUNT <= 10.
Row 101: 10 is allowed. Row 102: 15 is too high. Row 103: 5 is allowed. Row 104: NULL fails.
The result has two rows: Hemant with 10 and Keshav with 5.

Step 5: Query III:
ORDERDATE IS NOT NULL is true for rows 101, 103 and 104. MONTHNAME turns each date into its month name.
Row 101 gives March. Row 103 gives January. Row 104 gives December.
The result has three rows in this order: March, January, December.

Step 6: Query IV:
No filter is used, so the result has 4 rows. DAY takes the day part of the date.
Row 101 gives 1. Row 102 gives NULL because the date is NULL. Row 103 gives 20. Row 104 gives 25.

Final Answer:
I. Hemant, Neha, Keshav
II. Hemant 10 and Keshav 5
III. March, January, December
IV. 101 1, 102 NULL, 103 20, 104 25
Was this answer helpful?
0