Please provide the answer in MYSQL workbench /* 1. Write a SELECT statement that
ID: 3726761 • Letter: P
Question
Please provide the answer in MYSQL workbench
/* 1. 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.
This query would list category names only if there are products associated with the category.
SELECT DISTINCT category_name
FROM categories c JOIN products p
ON c.category_id = p.category_id
ORDER BY category_name */
categoreis table:
Columns:
products table:
Columns:
category_id int(11) AI PK category_name varchar(255)Explanation / Answer
SELECT DISTINCT category_name
FROM categories where category_id in ( select distinct category_id from products)
ORDER BY category_name;
Explanation:
Here we select distinct category_id from products table and project the distinct category_name from categories table for the corresponding category_id using a WHERE clause with IN keyword.
As there is no data given hence no output is possible.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.