7/31/2023 0 Comments Mysql limit![]() When a query is executed it first gets translated into a plan that is made up of several operators. Make your queries as simplistic as possible when doing LIMIT by gathering keys only.If you have all your "ducks in a row" (Have the four principles in mind for your query), you can get surprisingly good results. Doing LIMIT inside subqueries may not always be the answer because of the cardinality of indexes, the data content, and the result set size from the LIMIT.Then, I performed the necessary JOINs afterwards. This allowed me to get the last 40 articles using LIMIT. This subquery is buried three levels deep. Please notice the line in the query with the LIMIT FROM (SELECT id FROM articles ORDER BY date_created DESC LIMIT 40) A ON (AAA.id=CCC.article_id AND AAA.date_added=CCC.date_added) ![]() LEFT JOIN article_contents BBB ON AAA.id=BBB.article_id LEFT JOIN article_images B ON A.id = B.article_id In my answer to that question (May 16, 2011), I wrote the following query and tested it thoroughly: SELECTĪ.id,IFNULL(MAX(B.date_added),' 00:00:00') date_addedįROM (SELECT id FROM articles ORDER BY date_created DESC LIMIT 40) A I used those concepts to answer a very tough StackOverflow question about getting the top 40 articles from some tables : : Fetching a Single Row from Join Table. I learned these concepts by watching this YouTube Video (listen carefully through the French accent) These principles can go a long way if you can orchestrate them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |