What im trying ot do is update the first instance of a record based on contact_id.
I have a table of email addresses and corresponding contact_id's. Each contact may have more than one email address so the table can contain more than one instance of the same contact_id.
I want to update the corresponding is_primary field to '1', when I hit the first instance of each distinct contact_id.
I'm not too concerned about what ends up being the primary email address as long as everyone in the database has one.
Table Example:
contact_id | email | is_primary
---------------------------------------------
1001 | [email protected] |0
1001 | [email protected] |0
1002 | [email protected] |0
1003 | [email protected] |0
1003 | [email protected] |0
1003 | [email protected] |0
So the result im looking for would be:
contact_id | email | is_primary
---------------------------------------------
1001 | [email protected] |1
1001 | [email protected] |0
1002 | [email protected] |1
1003 | [email protected] |1
1003 | [email protected] |0
1003 | [email protected] |0
Have tried creating a temp table and macthcing to that, but query updated all is_primary fields. I know im missing something basic here, but my sql skills are limited.