Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    86

    [SQL]Problema con subquery

    Ciao a tutti.
    Ho questa query:

    select a.cod_ente, a.des_dann, a.targa, b.dt_avv
    from tab1 a, tab2 b
    where b.cod_sin = a.cod_sin
    and b.lg_avv = 'ROMA'
    order by b.dt_avv asc

    dove cod_sin è una chiave per tab1 e tab2

    Voglio aggiungere i seguenti campi:

    select a.cod_ente, a.des_dann, a.targa, b.dt_avv, b.lg_avv, c.indirizzo, c.dt_nasc, c.lg_nasc
    from tab1 a, tab2 b, tab3 c

    dove cod_ente è una chiave per tab1 e tab2

    Ho provato con la subquery
    select a.cod_ente
    from sinistro b, danneggiato a
    where b.lg_avv = 'ROMA'
    and b.cod_sin = a.cod_sin
    )

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    86

    [SQL]Problema con subquery

    Oops..
    Sono poco esperto in questo lavoro

    Ho provato con la subquery
    select a.cod_ente
    from tab2 b, tab2 a
    where b.lg_avv = 'ROMA'
    and b.cod_sin = a.cod_sin

    cioè

    select a.cod_ente, a.des_dann, a.targa, b.dt_avv, b.lg_avv, c.indirizzo, c.dt_nasc, c.lg_nasc
    from tab1 a, tab2 b, tab3 c
    where b.cod_sin = a.cod_sin
    and c.cod_ente in
    (select a.cod_ente
    from tab2 b, tab1 a
    where b.lg_avv = 'ROMA'
    and b.cod_sin = a.cod_sin
    )
    and b.lg_avv = 'ROMA'
    order by b.dt_avv asc

    Mi dà risultati duplicati

    Mi sapete dire come posso fare?
    Grazie

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    86

    Re:

    Ho risolto:

    select a.cod_ente, a.des_dann, a.targa, b.dt_avv, b.lg_avv, c.indirizzo, c.dt_nasc, c.lg_nasc
    from tab1 a, tab2 b, tab3 c
    where b.cod_sin = a.cod_sin
    and a.cod_ente = c.cod_ente
    and b.lg_avv = 'ROMA'
    order by b.dt_avv asc

    Grazie

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 © 2026 vBulletin Solutions, Inc. All rights reserved.