Hi All,
Not sure how to do this (or even if you can) but thought I would ask
anyway.
I have a database of names and would like to do a selection based on the
number or words in a name
eg the name "Peter Smith" has 2 words
the name "Peter John Smith" has 3 words
the name "Peter John Fred Smith" has 4 words
(sorry if this is too obvious but I am just trying to make myself clear)
So the selections I would like to do are based on the number of words in
the name.
IE I would like to select all names where there are 3 words in it for
instance. If there were such a function as words(string) which returned the
number of words in a string then the simple select syntax would be:
select * from names where words(name) = 3
Of course in MySql there is no such function (that I am aware of) - so any
ideas how I can achieve this result.
Thanking You
Clyde Engalnd
PS: one obvious solution is to add another field to the table eg NumWords
then write code to maintain this field with the correct nubmer of words in
a name. I was trying to avoid this and hoping to be able to just use native
MySql functions.