From: | James Olin Oden <joden(at)Lee(dot)k12(dot)nc(dot)us> |
---|---|
To: | Dan Delaney <dionysos(at)dionysia(dot)org> |
Cc: | PostgreSQL SQL Discussion <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: [SQL] Finding strings inside a field... |
Date: | 1998-06-29 22:10:50 |
Message-ID: | 81Jun28.170305edt.35713@gateway.lee.k12.nc.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Brook Milligan | 1998-06-29 22:28:03 | IN and subselects |
Previous Message | CJB | 1998-06-29 21:46:04 | Re: [SQL] gmake not found |