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

From: "Brett W(dot) McCoy" <bmccoy(at)lan2wan(dot)com>
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 21:36:20
Message-ID: Pine.LNX.3.96.980629172202.460D-100000@dragosani.lan2wan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 29 Jun 1998, Dan Delaney wrote:

> 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?

You'll want to use the LIKE operator, with '%' and '_' used as wildcard
operators similar to '*' and '?' used in the Unix CLI.

SELECT * from MyDB WHERE DESCRIPTION LIKE "%foobar%";

Brett W. McCoy
http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
"The number of UNIX installations has grown to 10, with more expected."
-- The UNIX Programmer's Manual, 2nd Edition, June, 1972

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tim J Trowbridge 1998-06-29 21:39:37 Re: [SQL] Finding strings inside a field...
Previous Message Dan Delaney 1998-06-29 21:28:02 Finding strings inside a field...