Link to home
Start Free TrialLog in
Avatar of Jeremy Leys
Jeremy LeysFlag for New Zealand

asked on

Remove duplicates but keep one for combination of two columns in MySQL

Hi,

I have a table heath3_mt_cfvalues that I need to de-dup data on, based on a combination of keys link_id and cf_id.

I have managed to find and remove duplicates that have a different `value` field contents. I now want to remove duplicates but leave one unique value on combination of keys  link_id and cf_id for each instance. What would be the query syntax to achieve this?

Table = heath3_mt_cfvalues
id PK int(11)
cf_id int(11)
link_id  int(11)
value mediumtext
attachment int(10)
counter int(11)
Check field text

My previous question:  Find duplicates for combination of two columns in a MySQL database
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A simple GROUP BY should do it.
 heath3_mt_cfvalues
SELECT cf_id, link_id, value, attachment, counter, Check FROM heath3_mt_cfvalues GROUP BY cf_id, link_id;

Open in new window

Avatar of Jeremy Leys

ASKER

Brilliant, I take my hat off to you :)
Thanks but I don't deserve that credit. Happy to help. Cheers, Paul