On Microsoft SQL Server 2008, I have a table with Products:
Id | Name | DefaultImageId
And one with Images:
Id | ProductId |
Check this out.
Update Products Set DefaultImageId = ( SELECT top 1 Id From Images Where 1=1 and Products.Id = Images.ProductId ORDER BY NEWID() )