Results 1 to 4 of 4
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    Need to update row in table based on two different criteria in other table


    I have two tables, Recordings (fields: RecordingID, song_id) and Songs (fields: SongID, Title, AlternateTitle). What I want is an update query that will do this (in pseudo code):

    Code:
    If Recordings.song_id = Songs.SongID and Songs.AlternateTitle="DELETE" THEN 
    update song_id to Songs.SongID where Songs.AlternateTitle="KEEP"
    I can't figure out how to do this, but I feel like there must be a way.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I feeling you've got contradictory criteria there, but the general technique would be to create a SELECT query that pulls the records you want to update, then change it to an UPDATE query and fill in the "Update To" line to
    Songs.SongID

    for the appropriate field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    The issue is I need rows with two different criteria, so a SELECT query can give me both but that doesn't help me. Let me try different pseudo code in hopes I can clarify what I need:

    Code:
    Update Recordings, Songs
    SET Recordings.song_id to (SELECT song_id FROM Songs where AlternateTitle="KEEP") 
    WHERE Recordings.song_id=Songs.SongID AND Songs.AlternateTitle="DELETE";


    Quote Originally Posted by pbaldy View Post
    I feeling you've got contradictory criteria there, but the general technique would be to create a SELECT query that pulls the records you want to update, then change it to an UPDATE query and fill in the "Update To" line to
    Songs.SongID

    for the appropriate field.

  4. #4
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    Here's something close to what I want. It is an actual update query, so it should be clear what I'm going for. However, it generates an error ("operation must use an updateable query") so clearly it's not correctly formed.

    Code:
    UPDATE [Copy of Recordings], [Songs (Compositions)] SET [Copy of Recordings].song_id = (SELECT [SongID] FROM Songs WHERE  ((([Songs (Compositions)].[Alternative title(s)])="KEEP")))
    WHERE ((([Songs (Compositions)].[Alternative title(s)])="DELETE"));

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-23-2014, 02:20 PM
  2. Replies: 1
    Last Post: 10-29-2012, 08:15 AM
  3. Replies: 6
    Last Post: 05-10-2012, 08:20 PM
  4. Replies: 3
    Last Post: 12-06-2011, 11:32 AM
  5. Replies: 4
    Last Post: 09-03-2009, 02:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums