Results 1 to 12 of 12

Thread: Problema SQL

  1. #1
    Lieutenant Commander Warbarbie's Avatar
    Join Date
    Nov 2004
    Location
    Rome
    Posts
    16.296

    Default Problema SQL

    Possibile copiare un campo di una tabella su un campo(con nome diverso) sulla stessa tabella?

    Tabella1

    Campo1 Campo2


    Travasare completamente i dati dal campo1 al campo2 in pratica

    Avevo provato con

    Update Tabella1 set Campo1(select campo2 from Tabella1)

    Help


  2. #2
    Chief Petty Officer
    Join Date
    Jan 2004
    Location
    Trento
    Posts
    1.127

    Default

    Update Tabella1
    set Campo1 = (select campo2 from Tabella1)
    from tabella1

    vado a memoria su dove mettere il "from tabella 1", ma e' circa cosi'

    Jeff
    "I'm not a stranger, I'm just a friend you haven't met yet"
    "il bello degli ingegneri è che hanno sempre una dote non sfruttata che un’altra parte di mondo avrebbe usato per guadagnarci i milioni. L’ingegnere no, fa calcoli. Fenomenale."
    "This program had an unexpected end. What I have to do? [R]etry, [I]gnor or [C]ancel?" "C[a]re a saw"

  3. #3
    Tunnel's Avatar
    Join Date
    Mar 2004
    Location
    Location.
    Posts
    14.756

    Default

    devi fare un inner join


    UPDATE [TAbDest]
    SET [ColDest] =
    FROM [TabDes] INNER JOIN
    [TabOri] ON [TabDes.ColDes]= [TabOrig.ColOrig]

    ovviamente per
    Tab=tabella
    Col=colonna
    Des=destinazione
    Ori=origine
    Last edited by Tunnel; 24th October 2008 at 11:55.
    on Camelot Unchained (alpha):
    Nichodemus <GildaDiVecchieGlorieInPensione> - LaClasseCheCura - ServerName [soon]
    PG dei giochi vari in spoiler
    Spoiler


  4. #4
    Lieutenant Commander Warbarbie's Avatar
    Join Date
    Nov 2004
    Location
    Rome
    Posts
    16.296

    Default

    Quote Originally Posted by Jeff View Post
    Update Tabella1
    set Campo1 = (select campo2 from Tabella1)
    from tabella1
    vado a memoria su dove mettere il "from tabella 1", ma e' circa cosi'
    Così però la subquery va in errore perchè l'uguale nn può essere confrontato con valori non univoci.
    Ho provato a sostituire l'uguale con IN ma nada.


  5. #5
    Lieutenant Commander Warbarbie's Avatar
    Join Date
    Nov 2004
    Location
    Rome
    Posts
    16.296

    Default

    Quote Originally Posted by Tunnel View Post
    devi fare un inner join


    UPDATE [TAbDest]
    SET [ColDest] =
    FROM [TabDes] INNER JOIN
    [TabOri] ON [TabDes.ColDes]= [TabOrig.ColOrig]

    ovviamente per
    Tab=tabella
    Col=colonna
    Des=destinazione
    Ori=origine
    E funziona anche se tabella di destinazione e di origine sono la stessa?
    Thx cmq


  6. #6
    Lieutenant Commander San Vegeta's Avatar
    Join Date
    Oct 2003
    Location
    Bologna
    Posts
    12.153

    Default

    scusa eh, ma un semplice

    update nometabella
    set colonnaDestinazione = colonnaSorgente

    non ti piace?
    I rubinetti a casa di Chuck Norris non perdono, vincono.

    In the beginning there was nothing...then Chuck Norris Roundhouse kicked that nothing in the face and said "Get a job". That is the story of the universe.

    Quote Originally Posted by Wolfo View Post
    Concordo e propongo ban temporanei per chi critica la topa , la topa non si critica , dal trombabile in su non si commenta in modo sgradevole.
    la tua ignoranza in materia e' raccapricciante
    -cit. Estrema, 2022

  7. #7
    Master Chief Petty Officer Rise-the-Sky's Avatar
    Join Date
    Sep 2004
    Posts
    2.485

    Default

    Questi post mi fanno comprendere quanto sono fortunato a usare postgre.

    Enjoy the "Update tabella SET campo1 = campo2;" experience
    spamm is life.

  8. #8
    Master Chief Petty Officer Rise-the-Sky's Avatar
    Join Date
    Sep 2004
    Posts
    2.485

    Default

    Quote Originally Posted by San Vegeta View Post
    scusa eh, ma un semplice

    update nometabella
    set colonnaDestinazione = colonnaSorgente

    non ti piace?
    Suppongo che non sia SQL standard per cui non tutti i DB lo accettino . (suppongo )
    spamm is life.

  9. #9
    Tunnel's Avatar
    Join Date
    Mar 2004
    Location
    Location.
    Posts
    14.756

    Default

    Quote Originally Posted by Rise-the-Sky View Post
    Questi post mi fanno comprendere quanto sono fortunato a usare postgre.
    Enjoy the "Update tabella SET campo1 = campo2;" experience
    no ma chiaro, è così. però avevo capito per 2 tabelle diverse. ahahah
    avevo letto velocemente e non reputavo possibile fosse un problema di update sulla stessa colonna, quindi son andato tranquillo con lo step 2
    Last edited by Tunnel; 24th October 2008 at 12:07.
    on Camelot Unchained (alpha):
    Nichodemus <GildaDiVecchieGlorieInPensione> - LaClasseCheCura - ServerName [soon]
    PG dei giochi vari in spoiler
    Spoiler


  10. #10
    Lieutenant Commander Warbarbie's Avatar
    Join Date
    Nov 2004
    Location
    Rome
    Posts
    16.296

    Default

    Pd.
    Buttato 1 ora del mio preziosissimo tempo


  11. #11
    Warrant Officer Ladro di anime's Avatar
    Join Date
    Apr 2004
    Location
    Trieste
    Posts
    2.802

    Default

    Povero sql, deturpato cosi

  12. #12
    Lieutenant Commander San Vegeta's Avatar
    Join Date
    Oct 2003
    Location
    Bologna
    Posts
    12.153

    Default

    Quote Originally Posted by Rise-the-Sky View Post
    Suppongo che non sia SQL standard per cui non tutti i DB lo accettino . (suppongo )
    no, è sql standard, pulito pulito

    l'update funziona a livello di "isolamento riga" quindi quando parli di colonne si intende il valore della colonna per la riga correntemente valutata

    nella fattispecie, set colonna1 = colonna2 significa che prende il valore della colonna2 e lo mette nella colonna1, in quella precisa riga... per ogni riga in esame, ovviamente
    I rubinetti a casa di Chuck Norris non perdono, vincono.

    In the beginning there was nothing...then Chuck Norris Roundhouse kicked that nothing in the face and said "Get a job". That is the story of the universe.

    Quote Originally Posted by Wolfo View Post
    Concordo e propongo ban temporanei per chi critica la topa , la topa non si critica , dal trombabile in su non si commenta in modo sgradevole.
    la tua ignoranza in materia e' raccapricciante
    -cit. Estrema, 2022

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
[Output: 89.04 Kb. compressed to 75.70 Kb. by saving 13.34 Kb. (14.98%)]