Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL question
Message
 
 
À
07/08/2009 02:49:04
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:
01416401
Message ID:
01416724
Vues:
56
If you only want one record per c1, c2, c3 then this simple select will work to show all records that are not correct
select T.* from myTable T 
INNER JOIN (select c1, c2, c3 from myTable group by c1,c2,c3 having count(*) >1) X on T.c1=X.c1  and T.c2=X.c2 and T.c3 = X.3
You can delete bad records based on that then
delete myTable from myTable inner join (select T.IDField from myTable T 
inner join (select c1, c2, c3 from myTable group by c1,c2,c3 
having count(*) >1) X on T.c1=X.c1  and T.c2=X.c2 and T.c3 = X.3)) X1 on myTable.IDField = X1.IDField 
LEFT JOIN (select min(T.IDField) as MinIDToKeep from myTable T 
inner join (select c1, c2, c3 from myTable group by c1,c2,c3 
having count(*) >1) X on T.c1=X.c1  and T.c2=X.c2 and T.c3 = X.3) group by C3) Keep 
on MyTable.IDField = Keep.MinIDToKeep where Keep.MinIDToKeep IS NULL
>Hi Grgory, Naomi, Walter
>
>I've read the whole tread and give a single answer.
>
>To the first, thank you for your work.
>Folks, there is no need to argue about the question I placed, it's not that urgent that you can not wait for me to express myself better.
>
>Noami, I have expressed myself wrong. I agree that one could have read my question the way you have done.
>
>For a given c3 there should be a single combination, I.E in the target of my import C1+C2+C3 could be a candidate key.
>I have to figure out every combination C3 that will not fullfill this.
>
>So from
>
>CREATE CURSOR Schnaps (c1 c(1), c2 c(1), c3c(1), i1 I)
>
>INSERT INTO Schnaps VALUES ('A', 'a', '1',01)
>INSERT INTO Schnaps VALUES ('A', 'b', '2',02)
>INSERT INTO Schnaps VALUES ('A', 'b', '3',03)
>INSERT INTO Schnaps VALUES ('A', 'b', '3',04)
>INSERT INTO Schnaps VALUES ('B', 'd', '4',05) &&
>INSERT INTO Schnaps VALUES ('B', 'd', '4',06) &&
>INSERT INTO Schnaps VALUES ('B', 'c', '4',07) &&
>INSERT INTO Schnaps VALUES ('B', 'c', '4',10) &&
>INSERT INTO Schnaps VALUES ('B', 'c', '4',11) &&
>INSERT INTO Schnaps VALUES ('A', 'a', '4',08) &&
>INSERT INTO Schnaps VALUES ('A', 'b', '3',09)
>
>
>I need the records with i1 in (5,6,7,8,10,11)
>
>Your solution will return only i1=8 but in this case it will mix up my target with duplicate definitions.
>
>If I add record
>
INSERT INTO Schnaps VALUES ('A', 'a', '4',12) &&
>your code will not even notice me.
>
>Anyway I found your code a great peace of work. One could try to modify it to figure out all with occurence less then maximal.
>(for 4 "A,a" 1 occurence "B,d" 2 and "B,c" 3 times,) so we trace out "A,a" and"B,d".
>But the import has the simple rule - just one definition. If I found more then one I create protocoll and keep the first occurence, whatever this means.
>
>So this thread is about the protocoll.
>
>Gregory, Walter
>
>your solutions both create the correct dataset. I have no idea wich one might be faster or better. Anyway both teach me something about SQL SELECT.
>
>Agnes
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform