Autor | Beitrag |
---|---|
poetflashimpactMi 2.5.12, 10:11 | Hallo Festzeit-Forum, Ich habe folgendes Problem: Tabelle 1: ID ;Name ;Preis ;Lagerbestand 1 ;PC01 ;999 ;4 2 ;PC02 ;899 ;16 Tabelle 2: ID ;Preis ;Lagerbestand 1 ;959 ;3 2 ;869 ;14 Nun möchte ich per PHP / MySQL die Spalte ID vergleichen und bei übereinstimmung in Tabelle 1 die werte von Tabelel 2 Aktualiseren. Kann mir jemand weiterhelfen? Vielen dank für die Bemühungen, Poetflashimpact |
StefanRaabMi 2.5.12, 12:23 | was wetsch du genau? eifach immer s gliche in de tabelle1 ha wie in tabelle2? also bimne update z.B. d ID1 in de tabelle2 de lagerbestand uf 4 update? bzw. de pris? |
poetflashimpactMi 2.5.12, 12:32 | danke für dini Antwort Tabelle 1 isch die wo vom System verwendet wird. 1. Wenn tabelle1.ID = tabelle2.ID ; 2. dann tabelle2.preis > tabelle1.preis tabelle2.lagerbestand > tabelle2.lagerbestand Beispiel Ausgangslag: Tabelle 1 ID ;Name ;Preis ;Lagerbestand 1 ;PC01 ;999 ;4 2 ;PC02 ;899 ;16 Tabelle 2 ID ;Preis ;Lagerbestand 1 ;959 ;3 2 ;869 ;14 Update durchgeführt: Tabelle 1 ID ;Name ;Preis ;Lagerbestand 1 ;PC01 ;959 ;3 2 ;PC02 ;869 ;14 lg poetflashimpact |
StefanRaabMi 2.5.12, 15:49 | UPDATE tabelle1 Set tabelle1.preis = tabelle2.preis, tabelle1.lagerbestand = tabelle2.lagerbestand WHERE tabelle1.id = tabelle2.id bi nid 100% sicher obs so got aber i meinti s müest go, bi "mega tabällene" vilicht eifach nit so performant, aber sowas füersch in de regel jo au nid bi jedem Siteufruef uf... |
bDaveMi 2.5.12, 16:52 | muesch luege dass dini tabellene uff InnoDB laufe. Das bewirkt das dini mysqlOperatione uff em redundantere System laufe (so hesch eh keini performance problem). über phpmyadmin kasch du d requestzit aluege um z luege wie lang dini operatione gönd. Ev. machsch no e biz Laufziitoptimierig ^^ |
StefanRaabMi 2.5.12, 18:22 | ev. no im where ine teste öbs nid scho korrekt isch, spart es paar schrib OPs, aber ebe wenns nid bi jedem Ufruef mues gmacht wärde wird das kei Problem geh ^^ |
IchWerdeEsSchaffenMi 2.5.12, 19:28 | INSERT INTO ta1AS Y (spalte1, spalte2, spalte3) FROM ta2 AS X WHERE X.ID =Y.ID VALUES(spaltevontabelle2, weiteregewünschte spalte); Also ich benutz PostGre SQL aber sött go glaub ich.... |
IchWerdeEsSchaffenMi 2.5.12, 19:32 | Villicht muesch where und values tüschle scho lang nix meh mit sql gmacht |
StefanRaabMi 2.5.12, 21:32 | Zitat: IchWerdeEsSchaffen du erstellsch mit INSERT aber e neue itrag in de tabälle... Update wär do scho s korrekte xDINSERT INTO ta1AS Y (spalte1, spalte2, spalte3) FROM ta2 AS X WHERE X.ID =Y.ID VALUES(spaltevontabelle2, weiteregewünschte spalte); Also ich benutz PostGre SQL aber sött go glaub ich.... aber i glaub mer chönts no chli verschönere das wo ich gschribe han, ha au scho lang nix me mit my sql gmacht |
backinblackMi 2.5.12, 22:15 | 1 mal bearbeitet, zuletzt Mo 6.8.12, 23:25 |
poetflashimpactDo 3.5.12, 16:24 | Hoi Zämme, viele dank für eüeri hilf, funktioniert i wand frei mit: UPDATE tabelle1 Set tabelle1.preis = tabelle2.preis, tabelle1.lagerbestand = tabelle2.lagerbestand WHERE tabelle1.id = tabelle2.id |