Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL question #2
Message
De
06/08/2009 15:21:54
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
06/08/2009 08:11:36
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Divers
Thread ID:
01416409
Message ID:
01416554
Vues:
87
This message has been marked as the solution to the initial question of the thread.
>>>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
>>
>>
>>SELECT c1, MIN(c2) as c2, c3, MIN(iOrder) as iOrder FROM schnaps GROUP BY 1,3
>>
>>
>>Cetin
>
>Cetin
>
>Sorry, no
>
>#1 DELETE not SELECT
>#2 c2 is MIN by coincidence
>
>
>	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',6)
>	insert into Schnaps values ('B', 'd', '4',5)
>	insert into Schnaps values ('C', 'a', '4',7)
>
>
>Result should be:
>
>('A', 'a', '1',1)
>('A', 'b', '2',2)
>('A', 'b', '3',3)
>('B', 'd', '4',5)
>
>
>IOW It should delete all records with a c3 that follows a occurence of c3 if the whoöe stuff is ordered by iOrder.
>
>In xBase:
>
>index on iorder tag _iOrder
>scan for !deleted()
> lc3 = c3
> skip
> dele for c3==lc3 rest
> locate for c3==lc3
>endscan
>
>
>message#1416414 works well -


When you have the select, delete is easier.
Select t1.* From Schnaps t1 ;
  INNER Join ;
  (Select Min(iOrder) As iOrder From Schnaps Group By c3) t2 ;
  ON t1.iOrder == t2.iOrder
Delete From Schnaps Where iOrder Not In ;
   (Select Min(iOrder) As iOrder From Schnaps Group By c3)
IMHO message#1416414 is more complex than needed.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform