Subject Re: [firebird-support] Like
Author Helen Borrie
At 09:29 AM 9/09/2005 +0200, you wrote:
>I´ve a table a table with a varchar field "Codigo".
>I use firebird 1.5 and a sentence like "select * from table where codigo
>like "046"" only some of the rows with codigo=046 are selected, but with
>this sentence:
>"select * from table where codigo like "%046%"" all rows are selected. what
>are happening? with the first sentrence all or none rows must be selected,
>or I´m wrong

1. Your first search returns only those rows that have codigo = '046',
because you have no wildcard character(s). LIKE is the keyword for doing a
wildcard search. There is no sense in using LIKE (which cannot use an
index) if you intend to do an equality search. Use "=" here and get the
benefit of an indexed search for an exact match.

2. The "%" character is a wildcard. It means that anything (any number of
characters, including none) can be in the position occupied by the
wildcard. In fact, LIKE '%046%' will find every string that has '046' in
it, in any position. So that is why the second query will find more rows.

3. You are using double quotes as your string delimiter. Use single
quotes. Double quotes mean something quite different in SQL syntax.