When I do the following query I get seemingly arbitrary results for most of the 
columns.

SELECT f.folder_name, COUNT(g.post_id), n.poster_name, p.file_name
 FROM users u, folders f, users_to_files g, posts p, posters n
  WHERE f.user_id = u.user_id AND u.user_id = 1 AND g.folder_id=f.folder_id 
   AND p.post_id=g.post_id AND p.poster_id=n.poster_id
  GROUP BY f.folder_name


Is it possible to give MySQL ordering commands for the columns that are collapsed 
together by a GROUP BY ?

The above query gives me the below where the ordering of the selected Poster & Photo 
seems arbitrary when what I want is Poster by alpha order ASC and Photo by alpha order 
ASC and one row per Folder.

| Folder  | COUNT(g.post_id)| Poster         |    Photo      |

| Animals | 15              | WildAnimalsFan |    Zebra.jpg  |

| Cars    | 34              | TheBMWFan      |    Z3_BMW.jpg |

What I really want is this where the Poster is alpha ASC and the Photo alpha ASC & 
there's only one row per Folder  :

| Folder  | COUNT(g.post_id)| Poster      |    Photo     |

| Animals | 15              | Animalia    |    Bear      |

| Cars    | 34              | AlfaFan     |    Ferrari   |

Is this possible in one query & if so how ? I've tried various combos of GROUP BY 
poster, photo etc. with & without HAVING but the best that gives me is this which is 
close but I only want one line per Folder, not one row for every Poster within every 
Folder.

| Folder  | COUNT(g.post_id)| Poster         |    Photo      |

| Animals | 15              | Animalia       |    Bear       |

| Animals | 15              | WildAnimalsFan |    Zebra.jpg  |

| Cars    | 34              | AlfaFan        |    Ferrari    |

| Cars    | 34              | TheBMWFan      |    Z3_BMW.jpg |

 

thanks,

- Sam.



---------------------------------
Do You Yahoo!?
Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail.

Reply via email to