MySQL: Finding duplicates across multiple fields -


background: employer has database powered old version of mysql (3.23). have been asked find duplicate serial numbers , mac addresses in database.

i able find duplicate serial numbers, since version of mysql doesn't support subqueries, had resort using temporary table. these 2 sql statements ended using:

create temporary table if not exists inventory_duplicate_serials select serial inventory serial not null group serial having count(serial) > 1  select devicename, model, inventory.serial inventory inner join inventory_duplicate_serials on inventory.serial = inventory_duplicate_serials.serial order serial 

now need find duplicate mac addresses. problem "inventory" table has 3 mac address fields (mac, mac2, , mac3). so, example, if value of item's "mac" field same value of item's "mac2" field, need know it. how go doing this? thank time.


update: solved. ended creating 2 temporary tables (inventory_all_macs , inventory_duplicate_macs). these 5 queries:

create temporary table if not exists inventory_all_macs select mac inventory mac != ''  create temporary table if not exists inventory_all_macs select mac2 mac inventory mac2 != ''  create temporary table if not exists inventory_all_macs select mac3 mac inventory mac3 != ''  create temporary table if not exists inventory_duplicate_macs select mac inventory_all_macs group mac having count(mac) > 1  select devicename, model, inventory_duplicate_macs.mac duplicatemac, inventory.mac, mac2, mac3 inventory_duplicate_macs inner join inventory on inventory.mac  = inventory_duplicate_macs.mac or inventory.mac2 = inventory_duplicate_macs.mac or inventory.mac3 = inventory_duplicate_macs.mac order inventory_duplicate_macs.mac, devicename, model 

thanks everybody!

create temporary table if not exists inventory_mac   select mac   inventory  insert inventory_mac   select mac2   inventory  insert inventory_mac   select mac3   inventory  create temporary table if not exists inventory_duplicate_mac   select mac, count(*) cnt   inventory_mac   group mac   having count(*) > 1   select devicename, model, im.mac, i.mac, i.mac2, i.mac3 inventory_duplicate_mac im   join inventory     on    i.mac  = im.mac        or i.mac2 = im.mac        or i.mac3 = im.mac order im.mac 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -