sql - How to delete in mysql if a column field has more than 2 words? -


difficult explain lets have table column called name contains both name , surname , company names.

in order eliminate company names want remove rows if field not made out of 2 part string name surname (i.e. has more 2 words in it)

example of table colums:

id - name - someothercolumns

the name may contain both first name , surname and/or company names jt trading inc

since person name contains 2 section (aaaa bbbbb) thinking using logic filter out deletion person names instead of companies.

you can select rows name has more 2 words in it. pick doesn't appear person.

it doesn't account cases company name thing entered , 1 or 2 words in length. might not take account situations middle name of person stored (i.e. 3 words in length) , possible entry of double-barrel surnames without hyphenation (such isaac forsyth mimsy)

using generic terms data structure isn't explained in question:

delete #dont# table (     round (        (         char_length(ltrim(rtrim(name)))         - char_length( replace ( name, " ", "") )      ) / char_length(" ")         ) > 1 

i haven't included commit stop people copy pasting without thinking through.


Comments