Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql to find duplicates
Message
From
17/07/2003 15:41:45
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00811118
Message ID:
00811253
Views:
13
>>Whoops! Mea culpa. I misread it.
>
>No problem. What did you *think* was wrong?

I was reading it faster than my brain could process and I saw half outside the parens and half inside as all one line. I my eyes said that you were not grouping on all the selected fields, which of course, you are.

Alan

>
>>I still like this way the best as it gives all the duplicates rather than just a list of the contents >of one of the duplicated fields.
>
>It all depends on what you need, right? <g>
>
>Mike
>
>>Alan
>>
>>>I like this way the best myself, but unfortunately, it is not ansi compliant, and won't work in VFP8 without setting enginebehavior first.
>>>
>>>Alan
>>>
>>>>Allen,
>>>>
>>>>How about
>>>>
>>>>
>>>>select * from lineitems ;
>>>>where lineitems_id IN (select lineitems_id from lineitems ;
>>>>                       group by 1 ;
>>>>                       having count(lineitems_id) > 1) ;
>>>>order by lineitems_id ;
>>>>into cursor curDupes
>>>>
>>>>
>>>>
>>>>>>>>>Hi,
>>>>>>>>>Can someone help me with the SQL to find all duplicates in a field?
>>>>>>>>>Thanks,
>>>>>>>>>Allen
>>>>>>>>
select KeyFld, count(*) as CntDups from TestDups group by 1 ;
>>>>>>>>     having CntDups > 1 ;
>>>>>>>>     into cursor curDupes
>>>>>>>>
>>>>>>>
>>>>>>>Sorry but I did get it...
>>>>>>>Keyfld for me is lineitems_id
>>>>>>>TestDups table is lineitems
>>>>>>>What's CntDups... a variable?
>>>>>>>
>>>>>>>Allen

>>>>>>
>>>>>>
>>>>>>CntDups becomes a calculated field in your query result (cursor).
>>>>>>Basically you are saying to group by "lineitems_id" and count how many show up. Then disregard the ones that show up only once and show only 2 or more instances ("having CntDups > 1").
>>>>>>
>>>>>>
>>>>>>select lineitems_id, count(*) as CntDups ;
>>>>>>from lineitems ;
>>>>>>group by 1 ;
>>>>>>having CntDups > 1 ;
>>>>>>into cursor curDupes
>>>>>>
>>>>>>
>>>>>>Clearer?
>>>>>
>>>>>Thank you. It's clearer and works but I needed another thing...
>>>>>What you gave me shows the duplicate record and the times it's duplicated, but I was trying to get the duplicate records, record by record. So that each record is listed.
>>>>>Thanks,
>>>>>Allen
Previous
Reply
Map
View

Click here to load this message in the networking platform