• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

albums and photos

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure there is a standard solution for this.

I am using ms-sql server

I have tblalbums, tblphotos

albums have photos

for an album there can be one photo that is featured (featured=1 in tblphotos)

I need to display a page where I show each album name with its number of photos and the featured photo.

what is the best sql for this?

I cann't have storedprocedures.

thanks for your help.

Brian
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,
Even without stored procs, you can do multiple queries. I recommend one query to get all the albumn names with the corresponding # of photos and another query to get the featured photo for each album. You could do it in one query, but it would be complex.
 
gao zhixin
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but two query is effectiveless... I think the best way it to use some feature to maintain a table where has a field contain the #, Ex. trigger?
I 'm not skilled in DB, so you can ignore my suggest...
 
Brian Smith
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may not be most best solution but it's easy. Since you are using a 1 for featured photo (and i am assuming a 0 for all non-featured) just use an Order By DESC clause to order the photos, the first will be your featured photo, then you can just count the records in the result set by iterating through it.
[ April 21, 2006: Message edited by: Brian Smith ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gao zhixin:
but two query is effectiveless...

Why is that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic