221k views
5 votes
Which of the following SQL statements will display the title of all books that have had multiple copies requested in a single order?

A) SELECT Title FROM Books WHERE Copies > 1;
B) SELECT Title FROM Books HAVING Copies > 1;
C) SELECT Title FROM Books GROUP BY Copies HAVING COUNT(Copies) > 1;
D) SELECT Title FROM Books JOIN Orders ON Books.BookID = Orders.BookID WHERE Copies > 1;

User Seif
by
7.5k points

1 Answer

4 votes

Final answer:

The correct SQL statement is not listed among the options but would need a JOIN to combine the Books and Orders tables, GROUP BY to aggregate the data by book title, and a HAVING clause to filter the results.

Step-by-step explanation:

The question asks which SQL statements will display the title of all books that have had multiple copies requested in a single order. To select data across multiple tables where a specific condition on a count is required, you typically have to use a JOIN to combine the tables and a GROUP BY clause accompanied by a HAVING clause to filter the grouped results. The correct answer is therefore not directly provided in the options listed, but it would look something similar to D) with the inclusion of a GROUP BY clause:

SELECT Title FROM Books JOIN Orders ON Books.BookID = Orders.BookID GROUP BY Title HAVING COUNT(Orders.Copies) > 1;

This statement joins the Books and Orders tables on the common BookID, groups the results by the Title of the books, and filters out the groups that have a count of copies requested greater than 1 using the HAVING clause.

User Michael Bavin
by
8.2k points