I have a query which includes LIMIT to the main table and JOIN.
My questions is that: what is coming before? the query finds the x rows of the LIMIT and then doing JOIN to these rows or doing first the JOIN on the all rows and just after that LIMIT?
LIMITApplies to the query to which it is applied. It will be applied to the query AFTER theJOINs in that query, but if the derived table isJOINed to other tables, that/thoseJOIN(s) comes after.e.g.
JOINbetween T1 and T2 occurs firstLIMIT10 is applied to result from the previous step, so only 10 records from this derived table will be used in the outer queryLIMIT20 is applied to the result of theJOINbetween X and YAlthough LIMIT is a specific keyword for PostgreSQL, MySQL and SQLite, the TOP keyword and processing in SQL Server works the same way.