SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using Limit with subquery

    I have a master table and a detail table and want to perform a query returning only a certain number of master records that can be processed as a limit so I can paginate the full set. So if each master has a different number of detail records, putting a limit on the query limits it based on the number of detail records which is the total number of records retrieved.

    In this case, do I need to do a master query first and then process all the detail queries based on the master return?

    Hope that makes sense, if not let me know.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by bostboy View Post
    In this case, do I need to do a master query first and then process all the detail queries based on the master return?
    that would work quite well, except you have a bit more coding to do in the application to "merge" the two result sets
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the input. I have decided to go that route and it so far works just fine and gives me more control and seems to process very efficiently as well. I am doing a master query and then a single detail query after building an IN clause with the first query key values and then will process the merge in PHP. Thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •