Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL
Message
De
17/11/2009 12:19:18
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Re: SQL
Versions des environnements
Environment:
C# 3.0
Database:
MS SQL Server
Divers
Thread ID:
01435087
Message ID:
01435234
Vues:
24
>>>>select distinct from (select T1.Fields from Table1 T1 UNION ALL Select T2.Fields from Table2 T2 etc.) X
>>>>
>>>>Or please explan in more details what exactly do you want.
>>>
>>>Thanks Naomi,
>>>
>>>Her is the statement written as you suggest.
>>>
>>>SELECT DISTINCT FROM(select Well_5.DailyRuntime, Well_5.DailyStarts, Well_5.DailyFlowrate from Well_5 union all
>>> select Well_6.DailyRuntime, Well_6.DailyStarts, Well_6.DailyFlowrate from Well_6)
>>>
>>>this returns an error 'Incorrect syntax near the keyword FROM'
>>>
>>>I have three additional tables representing other wells that have the same columns and also need to be included in this query. I also need to retrieve one of the date columns from any of the tables since they all have data for the requested date.
>>>
>>>Thanks again for your help,
>>>
>>>Jim
>>
>>You should alias the derived table and also you should have at least one field in field list part of the SELECT:
>>
>>SELECT DISTINCT ??????
>>       FROM (select Well_5.DailyRuntime, Well_5.DailyStarts, Well_5.DailyFlowrate from Well_5
>>             union all
>>             select Well_6.DailyRuntime, Well_6.DailyStarts, Well_6.DailyFlowrate from Well_6) Tbl1
>>
>>BTW SELECT Distinct is redundant in that case. If you use just use UNION not UNION ALL that will give you DISTINCT records
>>
>>
>>
>>select Well_5.DailyRuntime, Well_5.DailyStarts, Well_5.DailyFlowrate from Well_5
>>union
>>select Well_6.DailyRuntime, Well_6.DailyStarts, Well_6.DailyFlowrate from Well_6
>>
>
>I think I had some ideas why I wanted to use DISTINCT outside - don't remember right now. I wanted Jim to find this problem himself, but you gave it up :)

Ok, please be patient with me. The query returns three columns. What I am looking for is six columns with each row being a single day. The query also returns extraneous rows having null values in at least one column.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform