that's a good description, except there's a tiny problem with your logic
Quote:
SELECT DISTINCT Ordnum from Orders;
Lets say it returned records 1, 3, and 4. The following would be displayed:
Ordnum
1 11111
3 22222
4 33333
|
the problem is that SELECT DISTINCT does not display rows from the original table, it displays
values, and it returns these values as rows in a "new" table, the result set of the query
so it would be better to say it returned
47 11111
48 22222
49 33333
where the "new" row numbers are different from the original table
now, when you want to select rows from the original table, you can match them against this "new" table...
... but the big question is (and has always been) how do you exclude one of the 11111's and pick the other one? i mean, what determines which one you pick? because if you don't do anything about it,
both values of 11111 in the original table will match the 11111 in the "new" table
obviously, the answer is, you have to supply some other criterion
like, for example, pick the row that has 11111
and also has the highest city name (in this case, NYC)
once you specify that extra condition, it is easy to make a connection to the "new" table of distinct values
Code:
select Ordnum, Name, City,
from Orders XX
where City =
( select max(City)
from Orders
where Ordnum = XX.Ordnum )
in this example, we use a correlated subquery to select the highest City name of all the rows that have the same Ordnum as the row being considered
there is a way to do it with a join too, but i prefer the correlated subquery because it's very clear what it's doing
rudy