Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cool way to eliminate duplicate column values?
Message
From
07/04/2001 14:05:52
 
 
To
07/04/2001 10:26:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00493142
Message ID:
00493244
Views:
18
>Would this work ?
>
select distinct myField, recno() as rcno ;
> from myTable into cursor crsUnique nofilter
>select * from mytable where recno() in (select rcno from crsUnique)
It sure looks like it would work. Here's a method I came up with that does work but may depend on internal implementation of SELECT-SQL GROUP BY to get correct results.

Suppose I have work orders for parts I make (many-to-many relationship) and I want to create a table containing just the initial work order for each part. I can assume that the lowest work order number for a given part number is the initial work order for that part. So...
SELECT partnum,wonum;
  FROM workorders;
  ORDER BY partnum,wonum desc;
  INTO CURSOR uniq_wos NOFILTER
SELECT partnum,wonum;
  FROM uniq_wos;
  ORDER BY partnum;
  GROUP BY partnum;
  INTO CURSOR uniq_wos
This works because (apparently) GROUP BY selectitem returns the row of the last selectitem it finds in the source set as the representative row of the group....(makes sense if you're summing, averaging, etc). However, though it stands to reason that GROUP BY should work this way by definition, I do not know if that is a fact ... or it is just the way my version of VFP implements it.

The reason for using two selects is because the selection of the group row apparently occurs prior to ordering the result set.

If anyone can give further information about whether this method is risky or not I'd appreciate it.
"The Iron Fish: The water is cold...but the fish don't mind"
...Jay Jenks, boyhood chum
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform