Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389

    una query un pò complessa non so come strutturarla

    ho necessità di prelevare dei dati da 3 tabelle con delle condizioni
    secondo la mia esperienza dovrei strutturarla cosi:

    Codice PHP:
     $query mysql_query("SELECT * FROM tab1,tab2,tab3 WHERE tab1.campo1=tab2.campo1   and   tab1.id_prova= tab3.id and  tab2.id_prova=tab3.id "); 

    ma non funziona quando aggiungo il primo and
    come si dovrebbe strutturare questa query con quelle condizioni?

    mi sto scimunendo da ieri

    grazie ciao

  2. #2
    Hai provato con le parentesi ?

    Codice PHP:
    SELECT FROM tab1tab2tab3 WHERE (tab1.campo1=tab2.campo1) and (tab1.id_provatab3.id) and (tab2.id_prova=tab3.id)..... 

  3. #3
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    non va...

  4. #4
    Come hai strutturato le tabelle? Che errore ti da? come fai a capire che si blocca al primo and?

  5. #5
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    perchè se levo and mi stampa , se lo metto non stampa niente

    vi posto l'intero codice

    Codice PHP:

    $query 
    mysql_query("SELECT * FROM tab1,tab2,utenti WHERE ((tab1.campo=tab2.campo) and (tab1.id_utente=utenti.id) and (tab2.id_utente=utenti.id))"); 
                
    $listamysql_num_rows($query); 
                for (
    $x0$x$lista$x++) 
                { 
                    
    $provamysql_fetch_assoc($query); 
    echo 
    $prova['nome']."
    "
    ;
    echo 
    $prova['campo']."
    "
    ;

                } 
    mi dovrebbe stampare tutti i nomi(prelevati dalla tabella utenti, ma solo quelli che stanno nella tabella tab1 e tab2 in base all'id_utente)
    infatti in tab1 e tab2 ci sta un campo id_utente che sarebbe l'id che sta nella tabella utenti

    quindi vorrei stampare i nomi dei soli id che stanno nella tabella tab1 e tab2

    poi vorrei prelevare e stampare solo quei record che hanno il campo uguale tra tab1 e tab2

    non so se mi sono spiegato bene, sembra un pò contorto come discorso

  6. #6
    Hai provato ad eseguire la semplice Query dalla shell di MySQL (oppure da PhpMyAdmin)?

    Codice PHP:
    $sql "SELECT * FROM tab1,tab2,utenti WHERE ((tab1.campo=tab2.campo) and (tab1.id_utente=utenti.id) and (tab2.id_utente=utenti.id))"

    $query mysql_query($sql) OR DIE ("Errore Numero: ".mysql_errno()." - Descrizione: ".mysql_error()); 
    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  7. #7
    Prova con
    codice:
    select *
    from utenti, tab1, tab2
    where tab1.campo = tab2.campo and id_utente in (select id_utente from tab1) and id_utente in (select id_utente from tab2)
    non garantisco Dimmi che ti stampa...

  8. #8
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    Originariamente inviato da tonynsyde
    Prova con
    codice:
    select *
    from utenti, tab1, tab2
    where tab1.campo = tab2.campo and id_utente in (select id_utente from tab1) and id_utente in (select id_utente from tab2)
    non garantisco Dimmi che ti stampa...

    non va

  9. #9
    Sorry

  10. #10
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    Originariamente inviato da alcio74
    Hai provato ad eseguire la semplice Query dalla shell di MySQL (oppure da PhpMyAdmin)?

    Codice PHP:
    $sql "SELECT * FROM tab1,tab2,utenti WHERE ((tab1.campo=tab2.campo) and (tab1.id_utente=utenti.id) and (tab2.id_utente=utenti.id))"

    $query mysql_query($sql) OR DIE ("Errore Numero: ".mysql_errno()." - Descrizione: ".mysql_error()); 
    provato non va

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.