Received: from access1.lan2wan.com (root@access1.lan2wan.com [205.177.8.10]) by hub.org (8.8.8/8.7.5) with ESMTP id RAA23072 for ; Mon, 29 Jun 1998 17:44:16 -0400 (EDT) Received: from an2wan.com (bmccoy@pm1-24.lan2wan.com [205.177.8.64]) by access1.lan2wan.com (8.8.5/Config By A.D.Simmons) with ESMTP id SAA16380; Mon, 29 Jun 1998 18:09:42 -0400 (EDT) Received: from localhost (bmccoy@localhost) by an2wan.com (8.8.7/8.8.7) with SMTP id RAA00555; Mon, 29 Jun 1998 17:36:21 -0400 X-Authentication-Warning: dragosani.lan2wan.com: bmccoy owned process doing -bs Date: Mon, 29 Jun 1998 17:36:20 -0400 (EDT) From: "Brett W. McCoy" To: Dan Delaney cc: PostgreSQL SQL Discussion Subject: Re: [SQL] Finding strings inside a field... In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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