Wie aktualisieren Sie mehrere Felder aus einer anderen Tabelle in mysql?

Dies ist die Abfrage, die ich versuche zu erreichen:

update amdashboard
set (ASCID, ASCFirst, ASCLast, ASCOtherName, ASCAdd1, ASCAdd2,
     ASCCity, ASCState, ASCZip, ASCZip4, ASCY2007, ASCY2008, ASCY2009,
     ASCY2010, ASCY2011, ASCY2012, ASCEthnicity, ASCGender, ASCMaritalStatus)
= (select id, firstname, lastname, listingspousename, add1, add2,
          city, state, zip, zip4, y2007, y2008, y2009,
          y2010, y2011, y2012, Ethnicity, Gender, MaritialStatus
     from ASCNCOAClean
          inner join amdashboard
          on ASCNCOAClean.firstname = amdashboard.actorsfirst
          and ascncoaclean.lastname = amdashboard.actorslast)
    where exists (select id, firstname, lastname, listingspousename,
                         add1, add2, city, state, zip, zip4, y2007, y2008,
                         y2009, y2010, y2011, y2012, Ethnicity, Gender,
                         MaritialStatus
                    from ASCNCOAClean
                         inner join amdashboard
                         on ASCNCOAClean.firstname = amdashboard.actorsfirst
                         and ascncoaclean.lastname = amdashboard.actorslast);

Ich kann nicht ankommen dieses zu wirken...erhalten einen syntax-error auf die erste Klammer. So, ich dachte, ich würde versuchen, auf nur einem Feld. Ich versuchte dies:

update amdashboard
set ascid = (select ascncoaclean.id
         from ASCNCOAClean 
         where ASCNCOAClean.firstname = amdashboard.actorsfirst
                           and ascncoaclean.lastname = amdashboard.actorslast)
where exists (select ascncoaclean.id
         from ASCNCOAClean 
         where ASCNCOAClean.firstname = amdashboard.actorsfirst
                           and ascncoaclean.lastname = amdashboard.actorslast);

Diese jedoch zurück und Fehler 1242: Unterabfrage gibt mehr als 1 Zeile. Das scheint mir albern. Ich weiß, es wird mehr als eine Zeile zurückgegeben...ich will es, weil ich auf mehrere Zeilen aktualisieren.

Was bin ich?

Können Sie einige Beispiel-Daten oder aus der schema-Struktur?

InformationsquelleAutor The Hammer | 2013-04-02

Schreibe einen Kommentar