Answer the question
In order to leave comments, you need to log in
Why is the request taking so long to complete?
There are 3 tables: keywords, images, images_keywords
SELECT SQL_NO_CACHE *
FROM keywords
JOIN(
SELECT DISTINCT keywords.id
FROM keywords
JOIN images_keywords ON keywords.id = keyword_id
JOIN images ON image_id = images.id WHERE images.space = 1
) as ids ON keywords.id = ids.id
Answer the question
In order to leave comments, you need to log in
I do not understand why such a request is built.
Why not just
SELECT k.* --Или лучше перечислить столбцы для выборки
FROM keywords as k
JOIN images_keywords ON keywords.id = keyword_id
JOIN images ON image_id = images.id WHERE images.space = 1
SELECT DISTINCT keywords.id
FROM keywords
JOIN images_keywords ON keywords.id = keyword_id
JOIN images ON image_id = images.id WHERE images.space = 1
SELECT DISTINCT keyword_id
FROM images_keywords
JOIN images ON image_id = images.id WHERE images.space = 1
SELECT SQL_NO_CACHE *
FROM keywords
WHERE keywords.id IN (
SELECT DISTINCT keyword_id
FROM images_keywords
JOIN images ON image_id = images.id WHERE images.space = 1
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question