MySQL Forums
Forum List  »  Newbie

Re: REGEX (search for x OR y -- where both are integers)
Posted by: Felix Geerinckx
Date: August 02, 2005 12:58AM

Paul Smith wrote:
> If I run:
> SELECT * FROM table WHERE title REGEXP '50|233|1200|234|632'
> it seems that it'll match any records with those numbers in them.
> 50,500,5000
> 233,2331,2332, etc.

That's exactly the purpose of a REGEXP.

> Anyway to have a regular expression only return records where the ID equals (not contains) the
> value in the regex?

You should use an IN clause:

SELECT * FROM TABLE WHERE title IN (50, 233, 1200, 234, 632);

which, as added benefit, will use an index on title if you have defined one.

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: REGEX (search for x OR y -- where both are integers)
August 02, 2005 12:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.