![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
my ci2 table: id,businessunit, zonenumber,zoneid, ndc There are 874 records that have 1 or more duplicates across zones with the 4 columns in the group by making it unique. I only need to order 1 per business unit, but the zones have more than one ndc across the zones. select * FROM ci2 WHERE ndc is not null GROUP BY businessunit,zonenm,zoneid,ndc HAVING ( COUNT(*)> 1 ) How to change the select into a delete? I am reading on how to create a temp table. How do I get the unique records into the temp table? Then I drop the real table. tnx, |
#12
| |||
| |||
|
|
On 12-11-10 20:15, jr wrote: my ci2 *table: *id,businessunit, zonenumber,zoneid, ndc There are 874 records that have 1 or more duplicates *across zones with the 4 columns in the group by making it unique. *I only need to order *1 per business unit, but the zones have more than one ndc across the zones. select * FROM ci2 WHERE ndc is not null GROUP BY businessunit,zonenm,zoneid,ndc HAVING ( COUNT(*)> *1 ) How to change the select into a delete? I am reading on how to create a temp table. *How do I get the unique records into the temp table? *Then I drop the real table. tnx, Your query is basically the same as: SELECT * FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 And this can be rewritten as: DELETE FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 (untested, please backup your data first ;-) -- Luuk |
#13
| |||
| |||
|
|
On 12-11-10 20:15, jr wrote: my ci2 *table: *id,businessunit, zonenumber,zoneid, ndc There are 874 records that have 1 or more duplicates *across zones with the 4 columns in the group by making it unique. *I only need to order *1 per business unit, but the zones have more than one ndc across the zones. select * FROM ci2 WHERE ndc is not null GROUP BY businessunit,zonenm,zoneid,ndc HAVING ( COUNT(*)> *1 ) How to change the select into a delete? I am reading on how to create a temp table. *How do I get the unique records into the temp table? *Then I drop the real table. tnx, Your query is basically the same as: SELECT * FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 And this can be rewritten as: DELETE FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 |
#14
| ||||||
| ||||||
|
|
On Nov 13, 8:19*am, Luuk <L... (AT) invalid (DOT) lan> wrote: On 12-11-10 20:15, jr wrote: my ci2 *table: *id,businessunit, zonenumber,zoneid, ndc There are 874 records that have 1 or more duplicates *across zones with the 4 columns in the group by making it unique. *I only need to order *1 per business unit, but the zones have more than one ndc across the zones. select * FROM ci2 WHERE ndc is not null GROUP BY businessunit,zonenm,zoneid,ndc HAVING ( COUNT(*)> *1 ) How to change the select into a delete? I am reading on how to create a temp table. *How do I get the unique records into the temp table? *Then I drop the real table. tnx, Your query is basically the same as: SELECT * FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 And this can be rewritten as: DELETE FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 |
|
Hello, I still need the answer on this. Is this right? SELECT businessunit,zonenm,zoneid,sku,ndc, count(*) from ci2 group by businessunit,ndc having COUNT(concat(bu,ndc) > 1) It is not doing what I expect. |
|
The count column has mostly 1s, but shows some 2s (dupes) but I need all of those > 1 in a aggregate list. thanks, |
|
rowid | parent_rowid | label | data | +-------+--------------+----------+---------------------------------+ 1 | NULL | root | this is the document root | 2 | 1 | layer 1 | This is the first layer | 3 | 1 | layer 2 | This is the second layer | 4 | 3 | item 3 | This is also at the first layer | 5 | NULL | sqlyog | ????? | 6 | NULL | japanese | ????? | 7 | 3 | item 3 | This is also at the first layer | 8 | 3 | item 3 | This is also at the first layer | +-------+--------------+----------+---------------------------------+ |
|
rowid | parent_rowid | label | data | +-------+--------------+----------+---------------------------------+ 1 | NULL | root | this is the document root | 2 | 1 | layer 1 | This is the first layer | 3 | 1 | layer 2 | This is the second layer | 5 | NULL | sqlyog | ????? | 6 | NULL | japanese | ????? | 8 | 3 | item 3 | This is also at the first layer | +-------+--------------+----------+---------------------------------+ |
|
rowid | parent_rowid | label | data | +-------+--------------+----------+---------------------------------+ 1 | NULL | root | this is the document root | 2 | 1 | layer 1 | This is the first layer | 3 | 1 | layer 2 | This is the second layer | 5 | NULL | sqlyog | ????? | 6 | NULL | japanese | ????? | 8 | 3 | item 3 | This is also at the first layer | +-------+--------------+----------+---------------------------------+ |
#15
| |||
| |||
|
|
Your query is basically the same as: SELECT * FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 And this can be rewritten as: DELETE FROM ci2 WHERE ndc is not null AND (SELECT count(*) from ci2 GROUP BY businessunit,zonenm,zoneid,ndc)>1 I do not think this will do what the poster wants it to. That will not delete duplicates in the sense that there will be only one row of the duplicates left. That will delete ALL the rows that have the duplicate values, leaving no row that has those previously-duplicated values. |
![]() |
| Thread Tools | |
| Display Modes | |
| |