Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DISTINCT List
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01091597
Message ID:
01091602
Vues:
13
>The following query works - to a point.
>
>It returns ALL the invoice records. All invoice records for a station are marked
>with the same invoice #, user and Done Date.
>
>I need a list that is distinct on those 3 columns, so that I only get 1 invoice record
>for each combination of invoice #, user and done date.
>
>Thanks
>
>
>select ri.id,
>       st.station_name,
>       ri.invoice_no,
>       ri.user_name,
>       ri.done_date_time
>  from document doc
>  join media_order mo on mo.document = doc.id
>  join media_order_detail mod on mod.media_order = mo.id
>  join recon_info ri on ri.mod_dtid = mod.id
>  join station st on st.id = doc.station
>  where st.station_name= 'KTLA'
>
Just remove first two fields ,or make them aggregate
select MAX(ri.id)            AS Id,
       MAX(st.station_name) AS station_name,
       ri.invoice_no,
       ri.user_name,
       ri.done_date_time
  from document doc
  join media_order mo on mo.document = doc.id
  join media_order_detail mod on mod.media_order = mo.id
  join recon_info ri on ri.mod_dtid = mod.id
  join station st on st.id = doc.station
  GROUP BY ri.invoice_no, ri.user_name, ri.done_date_time
  where st.station_name= 'KTLA'
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform