Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COUNT is different that when selecting fields
Message
De
15/02/2014 11:23:55
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
COUNT is different that when selecting fields
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01594404
Message ID:
01594404
Vues:
51
I have a select like this:
SELECT COUNT(*)
 FROM
 (SELECT MAX(InvoiceDetail.Numero) AS InvoiceDetailNumero
 FROM Invoice
 INNER JOIN InvoiceDetail ON Invoice.Numero=InvoiceDetail.NoInvoice
 WHERE Invoice.NoCompany=32
 GROUP BY InvoiceDetail.NoInvoice) Invoice2
 INNER JOIN InvoiceDetail ON Invoice2.InvoiceDetailNumero=InvoiceDetail.Numero
 WHERE InvoiceDetail.NoStatus=7 AND InvoiceDetail.AddUser=1
This gives 115063 records.

Now, I would like to collect some field from InvoiceDetail. So, I do something like this:
SELECT InvoiceDetail.NoInvoice
 FROM
 (SELECT MAX(InvoiceDetail.Numero) AS InvoiceDetailNumero
 FROM Invoice
 INNER JOIN InvoiceDetail ON Invoice.Numero=InvoiceDetail.NoInvoice
 WHERE Invoice.NoCompany=32
 GROUP BY InvoiceDetail.NoInvoice) Invoice2
 INNER JOIN InvoiceDetail ON Invoice2.InvoiceDetailNumero=InvoiceDetail.Numero
 WHERE InvoiceDetail.NoStatus=7 AND InvoiceDetail.AddUser=1
This gives 118419.

Basically, if I change the field to something else, it always gives a different number of records.

Obviously, something is missing here. Anyone would know how I can extract some fields for the records related to the COUNT(*)?
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