"The Natural Philosopher" <t...@invalid.invalid> wrote in message
news:k5otll$c13$1...@news.albasani.net...
> Brian Cryer wrote:
>> "The Natural Philosopher" <t...@invalid.invalid> wrote in message
>> news:k5n1nc$1m9$1...@news.albasani.net...
>>> Salvatore wrote:
>>>> On 2012-10-17, SpreadTooThin <
bjobr...@gmail.com> wrote:
>>>>> I have a column with data that looks like:
>>>>>
>>>>> AB_XYZ
>>>>> BB_123
>>>>> 123456
>>>>>
>>>>> I need to get a list of a rows where this column's data has an _ as
>>>>> the 3rd character.
>>>>>
>>>>> Select c from table where c like '__!_' escape '!';
>>>>>
>>>>> Is that correct?
>>>>
>>>> It would be easier to use a query like this:
>>>>
>>>> SELECT c FROM `table` WHERE c LIKE '__\_';
>>>>
>>>> You don't need the "ESCAPE" clause. In fact, I'd recommend you not use
>>>> it.
>>>>
>>> Better
>>>
>>> SELECT c FROM `table` WHERE c LIKE '__\_%';
>>
>> Just be aware that this won't use any indexes, so performance for a large
>> table will be poor ... or (out of curiosity) can someone show me a way of
>> adding a suitable index?
>
>
> Doesnt LIKE use indices* on 'c'' if 'c' is indexed?
> Hmm. Not if the first char is a wildcard it seems.
<snip>
> *note CORRECT spelling.
OT: Interesting, not sure about that ("indexes" vs "indices"). My dictionary
has both. Google tells me that both are in use - although which is used
more seems to depend on which part of the world you are in - so where you
are, you are probably correct (and being a Brit I gather I should prefre
"indices"). Doing a search of the MySQL documentation and the dominate term
is "indexes" by far. But this is a moot point. What is reassuring is that I
wasn't missing a trick saying there it wouldn't use any indices/indexes.
--
Brian Cryer
http://www.cryer.co.uk/brian