Structured Query Language (SQL) · Class 12 · CBSE · Science Computer Science

A database has CUSTOMER(CustID, Name) and ORDERINFO(OrderID, CustID, Amount). Which query displays the names of customers who have not placed any ord…

Practice question from Structured Query Language (SQL) (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

hard · MCQ · Q-7E53BD

A database has CUSTOMER(CustID, Name) and ORDERINFO(OrderID, CustID, Amount). Which query displays the names of customers who have not placed any order?

  1. A.SELECT c.Name FROM CUSTOMER c LEFT JOIN ORDERINFO o ON c.CustID = o.CustID WHERE o.OrderID IS NULL;Correct answer
  2. B.SELECT c.Name FROM CUSTOMER c INNER JOIN ORDERINFO o ON c.CustID = o.CustID WHERE o.OrderID IS NULL;
  3. C.SELECT c.Name FROM CUSTOMER c RIGHT JOIN ORDERINFO o ON c.CustID = o.CustID WHERE c.CustID IS NULL;
  4. D.SELECT c.Name FROM CUSTOMER c LEFT JOIN ORDERINFO o ON c.CustID = o.CustID WHERE o.OrderID IS NOT NULL;

Solution

A LEFT JOIN retains every customer, including those without a matching order. For such customers, the columns from ORDERINFO contain NULL, so WHERE o.OrderID IS NULL selects exactly those customers.

More from Structured Query Language (SQL)

All of Structured Query Language (SQL)

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed