Re: [SQL] Finding strings inside a field...

Поиск
Список
Период
Сортировка
От James Olin Oden
Тема Re: [SQL] Finding strings inside a field...
Дата
Msg-id 81Jun28.170305edt.35713@gateway.lee.k12.nc.us
обсуждение исходный текст
Ответ на Finding strings inside a field...  (Dan Delaney <dionysos@dionysia.org>)
Ответы Re: [SQL] Finding strings inside a field...
Список pgsql-sql
> Hello all.
>    Could any one tell me if the following is possible using
> PostgreSQL?
>
> I want to be able do a SELECT and search for a string INSIDE OF a
> field. So, say I want to get all record in testtable which contain
> the word "foobar" inside the "description" attribute. The following
> will only get those records in which the "description" attribute
> contains ONLY the word "foobar":
>
> SELECT FROM testtable WHERE description='foobar';
>
> What do I need to do to get all the record that have "foobar"
> ANYWHERE within the "description" field?
>    Thanks a lot.
>  --Dan
>

The answer is to use the LIKE operator along with the wildcard character
'%' (why they did not use * I will never know).  Anyway, say you wanted to
find all streets that contained 'Zion' then you would write something like
(no pun intended):

   SELECT * FROM streets WHERE street LIKE '%Zion%';

And as long as you have your handy dandy Hebrew translator, Zion would be
come Tziyon...just kidding, you would get all the streets that contain
'Zion' in there name.

Hope this helps...james



В списке pgsql-sql по дате отправления:

Предыдущее
От: CJB
Дата:
Сообщение: Re: [SQL] gmake not found
Следующее
От: Brook Milligan
Дата:
Сообщение: IN and subselects