SQL UPDATE Subquery Question

Results 1 to 2 of 2

Thread: SQL UPDATE Subquery Question

  1. #1
    Join Date
    Dec 1969

    Default SQL UPDATE Subquery Question

    UPDATE pics SET photoLrg = (SELECT photoLrg FROM pics WHERE pin = 53), photoTn= (SELECT photoTn FROM pics WHERE pin = 53) WHERE pin = 1624;<BR><BR>Is a way to udate a record by using data from another record. These are in the same table. This works but seems a bit clunky. Nature of the best or any cleaner way to do this? There are 9 fields in all that will need this treatment.<BR><BR>Just wondering....<BR><BR>Paul

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL UPDATE Subquery Question

    is this in SQL Server?<BR><BR>DECLARE @photoLrg int, @photoTn int;<BR>SET @photoLrg, @photoTn = SELECT photoLrg, photoTn FROM pics WHERE pin = 53; -- think this should work, untested though<BR>UPDATE pics SET photoLrg = @photoLrg, photoTn = @photoTn WHERE pin = 1624;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts