Can you apply LIMIT on MySQL before LEFT JOIN another?

后端 未结 1 1195
梦谈多话
梦谈多话 2021-01-01 20:19

For example:

SELECT * FROM table_1 LIMIT 5 
LEFT JOIN table_2 AS table_1.id = table_2.id 
WHERE 1

Otherwise the engine takes all of table_1

相关标签:
1条回答
  • 2021-01-01 21:00

    You can do it by joining on a subquery instead of an actual table. Something like this should work:

    SELECT * FROM
        (SELECT * FROM table_1 LIMIT 5) as subq
        LEFT JOIN table_2 ON subq.id = table_2.id WHERE 1
    
    0 讨论(0)
提交回复
热议问题