18.2k views
5 votes
Write a SELECT statement that returns the same result set as this SELECT statement, but don’t use a join. Instead, use a subquery in a WHERE clause that uses the IN keyword. SELECT DISTINCT category_name FROM categories c JOIN products p ON c.category_id = p.category_id ORDER BY category_name

1 Answer

1 vote

Answer:

Hi there! The answer to this question is:

SELECT DISTINCT category_name FROM categories c WHERE category_id IN (SELECT category_id FROM products)

Please refer to the explanation below.

Step-by-step explanation:

This question is testing your knowledge on the database querying language to retrieve rows of data from the database. A fast way to retrieve data from the SQL database is by using a join if more than one table is being queried, since there is a direct link to the table. We can also write the statement instead with a sub-query included in the where clause to specify the filter conditions:

SELECT DISTINCT category_name FROM categories c WHERE category_id IN (SELECT category_id FROM products)

User MEdwin
by
5.6k points