dbTalk Databases Forums  

Pagination of joined table

comp.databases comp.databases


Discuss Pagination of joined table in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Flexor
 
Posts: n/a

Default Pagination of joined table - 01-25-2009 , 08:23 PM







Mysql 5.0.22,

I would think this is an ancient question but I haven't found an
answer for it in my searches.

Think of a weblog, with comments under each daily entry. (which isn't
actually my use case, but same relationships.) So,

Weblogs
-------------------------------
weblogid | title | body | postdate

Comments
commentid | weblogid | title | comment

What I want to do is display a page full of weblog posts, with the
first 10 comments under each one.

Seems simple enough, right? just do an inner join.

But- what if the posts have 2000 comments each, and need to be
paginated? (Again, I'm only using weblogs since it's familiar, this
could be any similar case). Or 10000 comments per post.

How do I do one select with an inner join, but only get the first 10
for each. So that each weblog post has the first 10 comments by date
underneath it?

OFFSET, LIMIT doesn't help me here, as far as I can see, unless this
is somehow possible with a mapped subselect or something like that?

I could do it without the join and just map over the results doing
individual queries for each post, but isn't that the biggest no-no in
database land?

Also I'd rather not write stored functions (is that what they're
called?), if possible, since this needs to be portable. (It's sad if
the only way to do this is custom functions, it's such a common need
of applications).

thanks



Reply With Quote
  #2  
Old   
Walter Mitty
 
Posts: n/a

Default Re: Pagination of joined table - 01-26-2009 , 12:02 AM







"Flexor" <yugyug66 (AT) hotmail (DOT) com> wrote

Quote:
Mysql 5.0.22,

I would think this is an ancient question but I haven't found an
answer for it in my searches.

Think of a weblog, with comments under each daily entry. (which isn't
actually my use case, but same relationships.) So,

Weblogs
-------------------------------
weblogid | title | body | postdate

Comments
commentid | weblogid | title | comment

What I want to do is display a page full of weblog posts, with the
first 10 comments under each one.

Seems simple enough, right? just do an inner join.

But- what if the posts have 2000 comments each, and need to be
paginated? (Again, I'm only using weblogs since it's familiar, this
could be any similar case). Or 10000 comments per post.

How do I do one select with an inner join, but only get the first 10
for each. So that each weblog post has the first 10 comments by date
underneath it?

OFFSET, LIMIT doesn't help me here, as far as I can see, unless this
is somehow possible with a mapped subselect or something like that?

I could do it without the join and just map over the results doing
individual queries for each post, but isn't that the biggest no-no in
database land?

Also I'd rather not write stored functions (is that what they're
called?), if possible, since this needs to be portable. (It's sad if
the only way to do this is custom functions, it's such a common need
of applications).

thanks

Your comments don't have a date attribute. How will you know which ones
belong in the first 10?



Reply With Quote
  #3  
Old   
Flexor
 
Posts: n/a

Default Re: Pagination of joined table - 01-26-2009 , 10:19 AM



On Jan 26, 1:02 am, "Walter Mitty" <wami... (AT) verizon (DOT) net> wrote:
Quote:
"Flexor" <yugyu... (AT) hotmail (DOT) com> wrote in message

news:886f0c70-01d8-4813-8f33-be9c88e38d1a (AT) v15g2000vbb (DOT) googlegroups.com...



Mysql 5.0.22,

I would think this is an ancient question but I haven't found an
answer for it in my searches.

Think of a weblog, with comments under each daily entry. (which isn't
actually my use case, but same relationships.) So,

Weblogs
-------------------------------
weblogid | title | body | postdate

Comments
commentid | weblogid | title | comment

What I want to do is display a page full of weblog posts, with the
first 10 comments under each one.

Seems simple enough, right? just do an inner join.

But- what if the posts have 2000 comments each, and need to be
paginated? (Again, I'm only using weblogs since it's familiar, this
could be any similar case). Or 10000 comments per post.

How do I do one select with an inner join, but only get the first 10
for each. So that each weblog post has the first 10 comments by date
underneath it?

OFFSET, LIMIT doesn't help me here, as far as I can see, unless this
is somehow possible with a mapped subselect or something like that?

I could do it without the join and just map over the results doing
individual queries for each post, but isn't that the biggest no-no in
database land?

Also I'd rather not write stored functions (is that what they're
called?), if possible, since this needs to be portable. (It's sad if
the only way to do this is custom functions, it's such a common need
of applications).

thanks

Your comments don't have a date attribute. How will you know which ones
belong in the first 10?
ok fine add a date attribute. or pretend they're orderd by title. Or
first 10 by id number. It doesn't matter, whatever.


Reply With Quote
  #4  
Old   
Lennart
 
Posts: n/a

Default Re: Pagination of joined table - 01-27-2009 , 02:13 PM



On 26 Jan, 03:23, Flexor <yugyu... (AT) hotmail (DOT) com> wrote:
Quote:
Mysql 5.0.22,

I would think this is an ancient question but I haven't found an
answer for it in my searches.

Think of a weblog, with comments under each daily entry. (which isn't
actually my use case, but same relationships.) So,

Weblogs
-------------------------------
weblogid | title *| body | postdate

Comments
commentid | weblogid | title | comment

What I want to do is display a page full of weblog posts, with the
first 10 comments under each one.

Seems simple enough, right? just do an inner join.

But- what if the posts have 2000 comments each, and need to be
paginated? *(Again, I'm only using weblogs since it's familiar, this
could be any similar case). *Or 10000 comments per post.

How do I do one select with an inner join, but only get the first 10
for each. *So that each weblog post has the first 10 comments by date
underneath it?

OFFSET, LIMIT doesn't help me here, as far as I can see, unless this
is somehow possible with a mapped subselect or something like that?

I could do it without the join and just map over the results doing
individual queries for each post, but isn't that the biggest no-no in
database land?

Also I'd rather not write stored functions (is that what they're
called?), if possible, since this needs to be portable. *(It's sad if
the only way to do this is custom functions, it's such a common need
of applications).

thanks
http://troels.arvin.dk/db/rdbms/#select-top-n

HTH
/Lennart



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.