Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [SQL]domanda difficile x me e banale x voi

    ho 2 tabelle nel mio db

    UTENTE
    id
    nomeutente
    [...]

    OFFERTA
    id
    id_offerente
    id_acquirente
    oggettovenduto
    [...]

    ovviamente id_offerente e id_acquirente sono chiavi esterne riferite a UTENTE.id

    devo fare un join tra le 2 tabelle in modo che ricercando in base ad "oggettovenduto" mi venga restituita una tabella dove ci siano una campo chiamato "offerente" che contenga UTENTE.username e uno chiamato "acquirente" che contenga anch'esso UTENTE.username

    cioè qualcosa del tipo

    SELECT * FROM UTENTE, OFFERTA
    WHERE (id_offerente = UTENTE.id OR id_acquirente = UTENTE.id) AND oggettovenduto = xxx

    e che nn so come creare i 2 campi che mi servono (offerente e acquirente) che nn devono contenere l'id ma l'username :master:

    aiutatemi x favore lo so che x voi geni è banale ma io non ci arrivo

  2. #2
    non sei molto chiaro. SPiegati un po' meglio o pubblica il link dove andare a vedere questo tuo lavoro.

    bye

  3. #3
    Originariamente inviato da sraddi
    non sei molto chiaro. SPiegati un po' meglio o pubblica il link dove andare a vedere questo tuo lavoro.

    bye
    nn c'è un link xkè sto provando in locale...

    cmq in poche parole io da quelle 2 tabelle devo fare una query che mi restituisca una campo nuovo "offerente" che contiene l'username corrispondente al'id contenuto appunto in id_offerente

    idem per "acquirente"

    cioè attraverso id_offerente e id_acquirente devo creare una campo offerente e uno acquirente che contengono l'username relativo all'id

    esempio
    Codice PHP:
    UTENTE
    id 
    nomeutente
    1      ciccio
    2      ciro

    OFFERTA
    id 
    id_offerente id_acquirente oggettovenduto
    1        1                 2            arance
    2        2                 1            patate

    RISULTATO 
    OFFERTA
    .id offerente acquirente oggettovenduto
    1             ciccio       ciro            arance    
    2             ciro         ciccio          patate 

  4. #4
    aiutatemi plz

  5. #5
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,923
    codice:
    select offerta.id,uno.nomeutente as offerente, due.nomeutente as acquirente, offerta.oggettovenduto
    from offerta 
    inner join utente as uno on offerta.id_offerente = uno.id
    inner join utente as due on offerta.id_acquirente = due.id

  6. #6
    Originariamente inviato da nicola75ss
    codice:
    select offerta.id,uno.nomeutente as offerente, due.nomeutente as acquirente, offerta.oggettovenduto
    from offerta 
    inner join utente as uno on offerta.id_offerente = uno.id
    inner join utente as due on offerta.id_acquirente = due.id
    grazie ! ora provo se funziona

    cmq praticamente crei 2 tabelle che si chiamano uno e due ???

    dimmi se ho ben capito

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.