Selection of entries that have only two words with SQL wildcards I have a table place that has a column called title. I want to select only those data which have only two words.
For example, if the table consists of a title named &quot;Buckingham Palace&quot;, I would have wanted it in my resultant table rather than having titles such as &quot;Tower Of London&quot; or &quot;Berlin&quot;. How can this be done in MySQL?
Note: Any title that has only one space in between will be considered. For example, &quot;St. Marc&quot; should also be selected.
I have tried
select title from place where title not like '% % %' 

I still get results in the table like St. Bishop's Palace (the entries which usually have words like St. or Mt.).
When I try that query with just a space extra added, I get unnecessary entries like Tower of God and Palace of Parliament.
select title from place where title not like ' % % % '.
Assuming you consider the space character as the delimiter to separate words (as per your examples) this query should do what you're looking for:
SELECT title
FROM Place
WHERE CHAR_LENGTH(SUBSTRING_INDEX(TRIM(title), ' ', 2)) = 0 -- Titles that don't have more than 1 space
    AND CHAR_LENGTH(SUBSTRING_INDEX(TRIM(title), ' ', 1)) &gt; 0 -- And Titles that have at least 1 space (effectively this conjoined predicate results in Title's with exactly 1 space, that isn't at the start or end, aka two words)

There's probably a simpler solution, but this will remove trailing and leading spaces from the title column then filter out anything that has more than 1 space (the first predicate) and filter out anything doesn't have at least 1 space (the second predicate). Also this syntax is only for MySQL, as you requested, but you also tagged your question as PostgreSQL (so you should either remove that tag or update the question with the information you need on PostgreSQL).