MySQL LIKE/RegExp help needed
From: Simon (spambucket_at_myoddweb.com)
Date: 03/26/05
- Next message: _andrea.l: "which tool to use to create form for a database?how to build a interfaces (or web pages) in easy way?"
- Previous message: Oli Filth: "Re: session variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Mar 2005 15:48:23 -0000
Hi,
I have a table with a column that contains many names, like "Ant Simon
Lucy",
if I was looking for one name in the string of names I would do...
SELECT * from classroom where name LIKE '%ant%'.
But the select above will return rows with names like 'antoine' or
'anthony'.
So I guess I could have a select with spaces...
SELECT * from classroom where name LIKE '% ant %'.
But that also does not work if 'ant' is the first or last entry in the list,
(like in the example above).
So to solve my problem I would need something like...
SELECT *
FROM classroom
WHERE
name LIKE "ant %" // first item in the list with more
OR name LIKE "% ant %" // neither the first nor last item in the list
OR name LIKE "% ant" // the last entry in the list
OR name = "ant" // the only entry in the list
But that does not look right, it does the job I guess but not in a very
elegant way.
Can someone give me a RegExp that would look for an exact name, (case
insensitive), in a string of names.
And how would I escape special characters in the string itself, (in weird
cases where the name I am looking for is something like "An^t"
Many thanks in advance,
Simon
- Next message: _andrea.l: "which tool to use to create form for a database?how to build a interfaces (or web pages) in easy way?"
- Previous message: Oli Filth: "Re: session variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|