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

    righe in piu tabelle e altro

    Salve , il problema nasce dalla paginazione voglio sapere in anticipo quanti risultati produrra una query e successivamente prendere i risultati

    il mio problema sta nel fatto che nn riesco a lavorare su piu tabelle cioe so di dover fare UNION tra le varie select ma nn ottengo il risultato sperato

    es.
    tb1(id_tb1,nome,cognome)
    tb2(id_tb2,nome,cognome)
    tb3(id_tb3,nome,cognome)

    1)
    vorrei conoscere prima il numero di righe presenti in tutte e tre le tabelle
    tipo

    SELECT count(*) as num_row
    from tb1
    union....

    solo che questa selezione non mi somma i risultati delle singole selezioni .

    2)
    vorrei i risultati di tutte e tre le tabelle in questo formato
    id , nome , cognome e questo sinceramente non so nemmeno come farla

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    1,326
    codice:
    select count(*) from(
    select comuni.id, comuni.item  from comuni where comuni.id=1
    union
    select comuni.id, comuni.item  from comuni where comuni.id=2
    union
    select comuni.id, comuni.item  from comuni where comuni.id=3
    union
    select comuni.id, comuni.item  from comuni where comuni.id<5
    )

    nel tuo caso:
    codice:
    select id_tb1 as id ,nome,cognome from tb1
    union
    select id_tb2 as id ,nome,cognome from tb2
    union
    select id_tb3 as id ,nome,cognome from tb3
    ricordati che la union ti restituisce solo righe diverse tra loro.


    ciao

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.