Answer the question
In order to leave comments, you need to log in
How Exist works?
Already Bosko rides from Exists. There is a request like this:
SELECT *
FROM authors
WHERE EXISTS (SELECT * FROM m2m_books_authors
WHERE authors.a_id=m2m_books_authors.a_id)
Answer the question
In order to leave comments, you need to log in
In general, I found a detailed explanation here https://stackoverflow.com/questions/5846882/how-do...
If in Russian: for a string from an external request, it is checked whether there is a string in the subquery that matches the condition (in the subquery). When a suitable row is found, the where exists condition will be satisfied for this row and the row will be included in the main selection.
The subquery is executed for each row of the outer query table.
I think it depends on what indexes and what kind of statistics there are on the tables. The task is similar to join algorithms.
For example, if there are indexes by fields, it is easier to bypass all records in the table in which there are fewer of them in ascending index, while moving along the index in a larger table and selecting records from there (for more details, see merge join).
Which particular algorithm is selected will be shown by the EXPLAIN command or the Visual Explain tool in MYSQL Workbench
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question