Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group BY with two fields
Message
De
15/09/2010 12:05:55
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Group BY with two fields
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01481287
Message ID:
01481287
Vues:
86
If I have the following SQL, I can group by the related field:
SELECT Event.RO_No FROM Event GROUP BY Event.RO_No
Now, I need to add a secondary field in regards to the grouping. Basically, RO_No is a foreign key. So, there are multiple occurences of it in the Event table. So, in the result, I need to grab a datetime field. If I do this, it will not work.
SELECT Event.RO_No,Event.DateTime FROM Event GROUP BY Event.RO_No
The reason is that Event.DateTime is not included in the group. But, in this case, I cannot include it in the group as it will take all the records from the table. As RO_No is not my primary key and there are multiple occurences of it in the table, I cannot use the first SQL and subset that into another SQL to get the related additional needed fields. How to adjust that to fit the requirements?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform