• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

albums and photos

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gao zhixin:
but two query is effectiveless...


Why is that?
reply
    Bookmark Topic Watch Topic
  • New Topic