Search code examples
mysqlsqlselectwhere-clausesql-like

MySQL SELECT values with more than three words


I currently have the following code

select *
FROM list
WHERE name LIKE '___'
ORDER BY name;

I am trying to get it so that it only shows names with three or more words. It only displays names with three characters I cannot seem to work out the correct syntax for this.

Any help is appreciated Thankyou


Solution

  • If you assume that there are no double spaces, you can do:

    WHERE name like '% % %'
    

    To get names with three or more words.

    If you can have double spaces (or other punctuation), then you are likely to want a regular expression. Something like:

    WHERE name REGEXP '^[^ ]+[ ]+[^ ]+.*$'