Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di Threepwood
    Registrato dal
    Feb 2003
    Messaggi
    2,107

    [SQL] problema con ordinamento!

    Salve a tutti .
    devo fare una query un po complicata.

    esempio :

    codice:
    SELECT USERNAME,ORDER_CODE   
    FROM ACCOUNT
    INNER JOIN  (select distinct(FK) from FATTURE order by date desc) tab
    on tab.FK = account.ID
    in pratica, voglio visualizzare SOLAMENTE l'ultimo pagamento di ogni utente.

    Sapete come fare? a me da errore e dice che non posso mettere l'order by nella subquery...
    Guybrush Threepwood

  2. #2
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    SELECT USERNAME,ORDER_CODE,MAX(DATE) AS ULTIMO_PAGAMENTO
    FROM ACCOUNT
    INNER JOIN FATTURE ON ACCOUNT.ID = FATTURE.FK
    GROUP BY USERNAME, ORDER_CODE

    Almeno credo...
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  3. #3
    select top 1 * ... order by id desc

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.