Gary W (gary@garywhittle.co.uk) writes:
[quoted text, click to view] > I am stuck on what is probably a very easy select query.
> The query is:
>
> Select Count(*), Distinct PID, ID, Name
> From Table 1
> Group By PID
>
> I get:
>
>| Count | PID | ID | Name |
> --------------------------------------------------------
>| 130 | GGT | 50 | Andy |
>| 60 | AAM | 51 | Graeme |
>| 360 | RGG | 52 | John |
>
>
>
> Now, there are 130 records with a PID of GGT. Why has "Andy" been
> returned in the row? There is a William in the row at the end of the
> alphabet. I want to sort INSIDE THE COUNT on Name Desc, but when I use
> Order By Name Desc, it ignores it. Very hard!!!
I have some difficulties to understand you are trying to do. For starters,
the query you posted, is illegal SQL, so what your actual query is, I don't
know.
So this is a bit too much of a guessing game for me to be willing to
take the task. A general advice for questions of this kind is that
you include:
o CREATE TABLE statements for your table.
o INSERT statements with sample data.
o The desired output from that sample data.
--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se
Books Online for SQL Server SP3 at