Skip to main content
edited tags
Link
skaffman
  • 404.6k
  • 96
  • 825
  • 775
Source Link
MartinHN
  • 19.9k
  • 20
  • 92
  • 137

Update SQL table with random value from other table

On Microsoft SQL Server 2008, I have a table with Products:

Id | Name | DefaultImageId

And one with Images:

Id | ProductId | Bytes

I want to run an Update statement, that updates the DefaultImageId on all records in the Products table with a random Id from the Images table that is related to the Product via the ProductId column.

Can anyone help out? Should be simple for any SQL Champ (Which is obviously not me)..