Answer the question
In order to leave comments, you need to log in
How can a query be optimized?
The task is as follows:
Get the types and names of products for the manufacture of which the most expensive parts are used;
There are 3 tables:
items [`id`, `view`, `name`, `description`] - Stores items
details [`id`, `name`, `price`, `unit_detail`] - Stores the parts that are used to make items
details_in_items [`id_item`, `id_detail`, `count`] - Stores the details used in item
[`id_item`,`id_detail`] in details_in_items table linked by primary key
My query is this:
SELECT view,name
FROM `items` WHERE id IN (SELECT id_item FROM details_in_items WHERE id_detail IN (SELECT id FROM `details` WHERE price=(SELECT MAX(price) FROM details)))
Answer the question
In order to leave comments, you need to log in
SELECT item.view, item.name, item.description
FROM items AS item
INNER JOIN details_in_items AS cross ON item.id = cross.id_item
AND cross.id_detail in (SELECT TOP 5 id FROM details ORDER BY price DESC)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question