143k views
2 votes
Which SQL statement retrieves unique names of publishers for books in the 'COMPUTER' category?

A. SELECT name, title, retail FROM books NATURAL JOIN publisher WHERE cost > 35.95;
B. SELECT UNIQUE name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER';
C. SELECT title, pubdate, name FROM publisher JOIN books USING (pubid);
D. SELECT title, cost, contact, phone FROM publisher JOIN books USING (pubid);

1 Answer

5 votes

Final answer:

The correct SQL statement to retrieve unique names of publishers for books in the 'COMPUTER' category is B. SELECT UNIQUE name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER';

Step-by-step explanation:

The correct SQL statement that retrieves unique names of publishers for books in the 'COMPUTER' category is B. SELECT UNIQUE name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER';

This statement uses the SELECT keyword to specify the columns to be retrieved, which is 'name' in this case. The UNIQUE keyword ensures that only unique names are returned. The FROM keyword is followed by the table names 'books' and 'publisher' which are joined using the NATURAL JOIN keyword. The WHERE clause filters the results to only include books in the 'COMPUTER' category.

The correct SQL statement for retrieving unique publisher names for books in the 'COMPUTER' category is 'SELECT DISTINCT name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER'', though the student's option used UNIQUE which is not standard SQL.

The SQL statement that retrieves unique names of publishers for books in the 'COMPUTER' category is B. SELECT UNIQUE name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER'. However, it's important to note that the keyword UNIQUE is not valid in all SQL databases. The standard SQL keyword for retrieving distinct records is DISTINCT, not UNIQUE. Therefore, the correct and universally accepted SQL statement should be SELECT DISTINCT name FROM books NATURAL JOIN publisher WHERE category = 'COMPUTER'. This query will give you a list of unique publisher names associated with books in the 'COMPUTER' category.

User Jauch
by
8.0k points