Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL question #2
Message
From
06/08/2009 11:55:32
Walter Meester
HoogkarspelNetherlands
 
 
To
06/08/2009 05:36:04
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01416409
Message ID:
01416510
Views:
54
Hi Agnes,

You want to delete those duplicate records, or just want to filter them out in a SQL Select.
If the latter:
SELECT* ;
	FROM Schnaps ;
	WHERE C3 NOT IN (SELECT C3 FROM (SELECT DISTINCT * FROM Schnaps) X GROUP BY C3 HAVING COUNT(*) > 1) OR ;
				NOT EXISTS(SELECT 1 FROM Schnaps X WHERE c3 = Schnaps.c3 AND iOrder < Schnaps.iOrder)
If the first
	DELETE FROM Schnaps WHERE iOrder NOT IN (;
	SELECT iOrder ;
		FROM Schnaps ;
		WHERE C3 NOT IN (SELECT C3 FROM (SELECT DISTINCT * FROM Schnaps) X GROUP BY C3 HAVING COUNT(*) > 1) OR ;
				NOT EXISTS(SELECT 1 FROM Schnaps X WHERE c3 = Schnaps.c3 AND iOrder < Schnaps.iOrder))

Walter,


>Gregory,
>
>if I change to
>
>	create cursor Schnaps ;
>	(	c1	c(1), ;
>		c2	c(1),; 
>		c3	c(1),;
>		iOrder	I ;
>	)
>	
>	insert into Schnaps values ('A', 'a', '1',1)
>	insert into Schnaps values ('A', 'b', '2',2)
>	insert into Schnaps values ('A', 'b', '3',3)
>	insert into Schnaps values ('A', 'b', '3',4)
>	insert into Schnaps values ('B', 'c', '4',5)
>	insert into Schnaps values ('B', 'd', '4',6)
>
>
>just to have an order (the import has some relevance in its order, but SQL wil not work with recordnumbers)
>
>What I need now is to delete any record with multiple definitions of c3 except the first one.
>
>Result should be:
>
>('A', 'a', '1',1)
>('A', 'b', '2',2)
>('A', 'b', '3',3)
>('B', 'c', '4',5)
>
>
>Agnes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform