troubleshooting Question

Help with SQL Syntax

Avatar of rovermedia
rovermediaFlag for Afghanistan asked on
SQL
9 Comments1 Solution237 ViewsLast Modified:
Hoping someone can help with a photo gallery migration...I'm not really proficient with SQL, but am 99% done.

I have two tables, PHOTOS and PHOTOS_ALBUMS

PHOTOS is essentially all the pictures in the gallery (id), along with id of the uploader (creator), and what Album those pictures belong to (albumid).

ALBUMS is all the albums (id), the user that created it (creator), and what Photo should be set as the thumbnail for the album (photoid)

I want to set the thumbnail for all the albums.  Some users have multiple albums.  I want the thumbnail to be the last photo they uploaded to each album.

So I need a query that will

A) Go through PHOTOS and select the last id from each albumid
B) In ALBUMS set photoid for each album to the last id selected above

Here are some sample tables:

PHOTOS

ID = 1
ALBUMID = 26
CREATOR = 9647
FILE: imagepath/81729.jpg

ID = 2
ALBUMID = 26
CREATOR = 9647
FILE: imagepath/0458435.jpg

ID = 3
ALBUMID = 35
CREATOR = 9647
FILE: imagepath/7347328974.jpg


ALBUMS

ID = 26
CREATOR = 9647
PHOTOID =

So in the example above, I'd want to populate alumbs.photoid with the last photos.id (in this case, 2).  Of course I have 100,000 users and 250,000 albums to do this for.

I know I could be clearer, but it's 3:30 AM here and my mind is fried...even I can barely make sense of what I am writing at this hour!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros