[MySQL 4.0] Aus Tabelle Teile in eine andere kopieren

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [MySQL 4.0] Aus Tabelle Teile in eine andere kopieren

    Guten Tag,

    als ich damals mit php/myadmin anfing hatte ich noch nicht so die Ahnung vom Tabellendesign. Nun soll eine Tabelle umgestellt werden.

    Es handelt sich dabei um eine Tabelle mit Sprachen als Spalten. 'Keyval' ist dabei der Index auf Deutsch und die Spalten stellen die Übersetzungen dar.

    Die Tabelle 'translation' sieht folgendermaßen aus:

    keyval |de | en | fr | es | it | el

    Ein typischer Eintrag wäre:

    apfel | Apfel |apple | irgendwas | irgendwas | irgendwas

    Nun brauche ich aber nicht jede Spalte ausgefüllt.

    Ich möchte die Tabelle aber so haben:

    id | lang | keyval | trans

    Dann sähe ein Eintrag z.B. so aus:

    1 | de | apfel | Apfel
    2 |en | apfel | apple
    ...

    Wie macht man das ? Habe keine Lust die Tabelle von Hand neu zu erstellen.
    Pickel ? Übergewicht ? Depressionen ?
    Brot, Kartoffeln und Milch sind Gift!
    http://www.paleofood.de

  • #2
    Öhm, übnerflüssige Felder löschen und die anderen einfach umbenennen/umformartieren?!?
    h.a.n.d.
    Schmalle

    http://impressed.by
    http://blog.schmalenberger.it



    Wichtige Anmerkung: Ich habe keine Probleme mit Alkohol ...
    ... nur ohne :-)

    Kommentar


    • #3
      probiere mal:

      insert into tblNew (id, lang, keyval, trans) from
      (select 'NULL', 'de', keyval, de from translation where * union
      select 'NULL', 'en', keyval, en from translation where * union
      select 'NULL', 'fr', keyval, fr from translation where * union
      ....)

      wobei where * = where de (en,fr,....) not is null, entsprechend der selektierte Spalte ersetzen
      Zuletzt geändert von asp2php; 28.07.2004, 13:39.

      Kommentar


      • #4
        Hallo asp,

        habe das mal für mich umgeschrieben:


        INSERT INTO translation1 (id, lang, keyval, trans) FROM
        (SELECT 'NULL', 'de', keyval, de FROM translation WHERE de NOT IS NULL union
        SELECT 'NULL', 'en', keyval, en FROM translation WHERE en NOT IS NULL union
        SELECT 'NULL', 'fr', keyval, fr FROM translation WHERE fr NOT IS NULL
        union
        SELECT 'NULL', 'it', keyval, fr FROM translation WHERE it NOT IS NULL
        union
        SELECT 'NULL', 'es', keyval, fr FROM translation WHERE es NOT IS NULL union
        SELECT 'NULL', 'el', keyval, fr FROM translation WHERE el NOT IS NULL union)

        Bevor ich das ausprobiere nochmal eine kurze Frage.

        Wozu soll das SELECT 'NULL' gut sein ? Dann müsste es je eine Spalte names NULL geben.
        Pickel ? Übergewicht ? Depressionen ?
        Brot, Kartoffeln und Milch sind Gift!
        http://www.paleofood.de

        Kommentar


        • #5
          habe einfach angenommen, dass id bei dir auto_increment ist. null bewirkt, dass id sich automatisch erhöhnt.

          Kommentar


          • #6
            Hmm,

            habe es so wie oben ausgeführt.
            Es kommt eine Fehlermeldung:


            MySQL meldet:
            #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (
            SELECT 'NULL', 'de', keyval, de
            FROM translation
            WHER

            In Tabelle 'translation1' ist kein einziger Eintrag nach der Ausführung.
            Zuletzt geändert von antman; 28.07.2004, 14:26.
            Pickel ? Übergewicht ? Depressionen ?
            Brot, Kartoffeln und Milch sind Gift!
            http://www.paleofood.de

            Kommentar


            • #7
              Müsste es nicht eher so sein ?

              INSERT INTO translation1 (id, lang, keyval, trans) FROM
              (
              SELECT 'NULL', de, keyval, de FROM translation WHERE de NOT IS NULL union
              SELECT 'NULL', en, keyval, en FROM translation WHERE en NOT IS NULL union
              SELECT 'NULL', fr, keyval, fr FROM translation WHERE fr NOT IS NULL union
              SELECT 'NULL', it, keyval, fr FROM translation WHERE it NOT IS NULL union
              SELECT 'NULL', es, keyval, fr FROM translation WHERE es NOT IS NULL union
              SELECT 'NULL', el, keyval, fr FROM translation WHERE el NOT IS NULL
              )


              PS: Geht aber auch nicht. Gleiche Fehlermeldung.
              Pickel ? Übergewicht ? Depressionen ?
              Brot, Kartoffeln und Milch sind Gift!
              http://www.paleofood.de

              Kommentar


              • #8
                Folgendes geht auch nicht.

                INSERT INTO translation1 (id, lang, keyval, trans) FROM
                (
                (SELECT 'NULL', de, keyval, de FROM translation WHERE de NOT IS NULL) UNION
                (SELECT 'NULL', en, keyval, en FROM translation WHERE en NOT IS NULL) UNION
                (SELECT 'NULL', fr, keyval, fr FROM translation WHERE fr NOT IS NULL) UNION
                (SELECT 'NULL', it, keyval, fr FROM translation WHERE it NOT IS NULL) UNION
                (SELECT 'NULL', es, keyval, fr FROM translation WHERE es NOT IS NULL) UNION
                (SELECT 'NULL', el, keyval, fr FROM translation WHERE el NOT IS NULL)
                )
                Pickel ? Übergewicht ? Depressionen ?
                Brot, Kartoffeln und Milch sind Gift!
                http://www.paleofood.de

                Kommentar


                • #9
                  ich sagte ja auch "probieren" . habe wenig mit MySQL zu tun und i.M. keine Zeit zu testen, vielleicht heute abend oder so ...

                  Kommentar


                  • #10
                    Servus

                    versuchs mal mit

                    insert into ziel_tabelle(spalte1, spalte2, spalte3) select spalte1, spalte2, spalte3 from Quelltabelle


                    sollte gehen

                    gruß

                    Matthais
                    Wusstet ihr schon?
                    Wer später bremst ist länger schnell!

                    Die wahrscheinlich beste Funktion in PHP ist mysql_error(), doch leider auch die unbekannteste!

                    Kommentar

                    Lädt...
                    X