php - Find cells with more than one email and separate them into different tables with all of the other information the same -
before
id | name | address | email =============================================================================== 1 | bob | 999 bob street, uk | bob@email.com 2 | jimmy | 123 jimmy house, usa | jimmy@email.com jimmy-partner@email.com
ok here problem, have 10,000+ rows looking id 1 & 2. of them have 3-6 emails per cell when of them should have one.
i need way select rows have 2 or more emails, copy whole row , replace copied row 1 of 2 emails have own separate row.
after
id | name | address | email =============================================================================== 1 | bob | 999 bob street, uk | bob@email.com 2 | jimmy | 123 jimmy house, usa | jimmy@email.com 3 | jimmy | 123 jimmy house, usa | jimmy-partner@email.com
thank suggestions provide useful information can used in future.
you can select rows more 1 email finding rows have more 1 @
in email column:
select * test_table2 (length(email) - length(replace(email, '@', ''))) > 1
then can process result in php , add more rows needed.
as mentioned in comments, might not best way organize data, indeed address question.
play here: http://sqlfiddle.com/#!2/d1f77/10
Comments
Post a Comment