Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 10:16 AM
Wilhelm
 
Posts: n/a
Default Order by attribute in child table

Hi all,

I've been thinking about it, and I'm a bit stumped, and wondered if
anyone here could help.

I have two tables, an albums and a photos table. An album contains
many photos. I want to get a list of albums ordered by the most
recent photo in the album. Basically, I want to be able to order
albums by the latest creation date of a photo in the album.

How would one go about doing that? I was thinking a correlated
subquery of some sort, but I've never have seen an example to use it
right after ORDER BY and I can't seem to get it to work myself.

As an alternative, perhaps it would be easier to update a new field in
the albums table called "last_uploaded_on" that gets timestamped on
every upload, and "order by" on that?

Thanks in advance.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 10:16 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Order by attribute in child table

Wilhelm wrote:
> Hi all,
>
> I've been thinking about it, and I'm a bit stumped, and wondered if
> anyone here could help.
>
> I have two tables, an albums and a photos table. An album contains
> many photos. I want to get a list of albums ordered by the most
> recent photo in the album. Basically, I want to be able to order
> albums by the latest creation date of a photo in the album.
>
> How would one go about doing that? I was thinking a correlated
> subquery of some sort, but I've never have seen an example to use it
> right after ORDER BY and I can't seem to get it to work myself.
>
> As an alternative, perhaps it would be easier to update a new field in
> the albums table called "last_uploaded_on" that gets timestamped on
> every upload, and "order by" on that?
>
> Thanks in advance.
>
>


The CREATE TABLE statements and sample data would be of great help in
your query. Otherwise we can only guess.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 10:16 AM
Captain Paralytic
 
Posts: n/a
Default Re: Order by attribute in child table

On 6 May, 23:58, Wilhelm <iam...@gmail.com> wrote:
> Hi all,
>
> I've been thinking about it, and I'm a bit stumped, and wondered if
> anyone here could help.
>
> I have two tables, an albums and a photos table. An album contains
> many photos. I want to get a list of albums ordered by the most
> recent photo in the album. Basically, I want to be able to order
> albums by the latest creation date of a photo in the album.
>
> How would one go about doing that? I was thinking a correlated
> subquery of some sort, but I've never have seen an example to use it
> right after ORDER BY and I can't seem to get it to work myself.
>
> As an alternative, perhaps it would be easier to update a new field in
> the albums table called "last_uploaded_on" that gets timestamped on
> every upload, and "order by" on that?
>
> Thanks in advance.


You would do it using a JOIN (not a correlated sub-query). However as
Jerry points out, without further info it is difficult to be more
precise in our advice.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62